Comments (5)
There is a way to build multiple themes in one project using less-loader:
This is the minimum configuration required for webpack:
{
resolve: {
alias: {
'../../theme.config$': path.join(paths.appSrc, '/semantic-ui/theme.config')
}
},
module: {
rules: [
{
test: /\.less$/,
use: [
{
loader: "less-loader",
options: {
additionalData: (content, loaderContext) => {
const { resourceQuery } = loaderContext;
const theme = /[?&]theme=([^?&]+)/.exec(resourceQuery);
if (theme) {
console.log("building custom theme: " + theme[1]);
return "@custom_theme: " + theme[1] + ";" + content;
}
return content;
},
},
},
],
},
],
},
}
or use craco config:
const CracoLessPlugin = require("craco-less");
module.exports = {
plugins: [{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
additionalData: (content, loaderContext) => {
const { resourceQuery } = loaderContext;
const theme = /[?&]theme=([^?&]+)/.exec(resourceQuery);
if (theme) {
console.log("building custom theme: " + theme[1]);
return "@custom_theme: " + theme[1] + ";" + content;
}
return content;
}
}
}
}]
};
In your theme.config you can now use multiple site directories or do other customizations based on the loaded theme:
/* Path to site override folder */
@siteFolder : '../../src/semantic-ui/@{custom_theme}/site';
Now you are able to lazy load your theme at runtime by adding a JS module for each theme like this one (./src/semantic-ui/dark.js
):
import 'semantic-ui-less/semantic.less?theme=dark';
To load the theme based on a query string for example you could do this in your main module:
const urlParams = new URLSearchParams(window.location.search);
const theme = urlParams.get('theme');
if (theme === 'dark') {
import('./semantic-ui/dark.js').then(render).catch(console.error);
} else {
import('./semantic-ui/light.js').then(render).catch(console.error);
}
const render = () => {
// theme is now loaded. render your app...
}
from semantic-ui-less.
Thanks for the question. Have the same problem here... How build many themes using Webpack in order to use theme with a Theme selector in a React app ?
from semantic-ui-less.
@andrewplummer Were you ever able to find a solution for this?
from semantic-ui-less.
@aautem not really.. I find overriding the theming cumbersome anyway so I've been manually importing the specific styles I need for "functional styles" (like hiding/showing modals) and writing everything else from scratch
from semantic-ui-less.
@skolmer, in case you are still watching this, any insights on how to make your proposed solution work dynamically on re-render (based on some component prop for example) instead of page reload?
from semantic-ui-less.
Related Issues (20)
- Does this include icons?
- Recursive variable definition with less 3.x HOT 7
- Request: please add 'css' Less 'Import Option' to font imports HOT 5
- Failed to compile
- Use @brandFontName for brand icon's font-family CSS rule
- Way to suppress colors completly ? HOT 1
- Certain calc fields not generated correctly HOT 2
- Incorrect fontPath in default theme HOT 1
- site.variables not available after importing semantic.less
- Provide Readme
- Can't resolve '../../theme.config' HOT 2
- Provide easy way to generate your own colors HOT 1
- Cannot create property '_index' on string '!important': after upgrading [email protected] to @3.10.x HOT 3
- ModuleNotFoundError HOT 1
- Bug? The list item of nested list are invisibility. HOT 1
- How to remove unused components HOT 2
- Can't resolve theme.less when configuring sematic-react-ui HOT 1
- How to resolved this Error: the first argument to unit must be a number HOT 13
- Confused UI Labeled input HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from semantic-ui-less.