I finally found a solution. What I did is generate the css with a variable ($theme
)having different values for each generated css file. And in my code, my style depends on the value of $theme
.
It is working with (yes, these are old version. Sorry):
"webpack": "2.2.0",
"webpack-combine-loaders": "2.0.3",
"multi-loader": "git://github.com/sshmyg/multi-loader.git#cbaa35f8936a939968adb78301be0204e36f30cd",
"extract-text-webpack-plugin": "git://github.com/ONE-LOGIC/extract-text-webpack-plugin.git#831af7b65ce749069993e60bd9cb51c637d4e98b",
then my webpack config contains this:
const extractDark = new ExtractTextPlugin({ filename: `css/style.dark.css`, allChunks: true });
const extractLight = new ExtractTextPlugin({ filename: `css/style.light.css`, allChunks: true });
...
config.module: {
rules: [
{
test: /\.css$/,
use: extractDark.extract({
fallback: 'style-loader',
use: [
{ loader: 'css-loader', query: { sourceMap: true } },
{ loader: 'postcss-loader' },
],
}),
}, {
test: /\.css$/,
use: extractLight.extract({
fallbackLoader: 'style-loader',
use: [
{ loader: 'css-loader', query: { sourceMap: true } },
{ loader: 'postcss-loader' },
],
}),
},
{
test: /\.scss$/,
use: multi(
combineLoaders(extractDark.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
}, {
loader: 'resolve-url-loader',
}, {
loader: 'sass-loader',
options: {
includePaths: [],
sourceMap: true,
data: '$theme: dark;',
},
},
],
})),
combineLoaders(extractLight.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
}, {
loader: 'resolve-url-loader',
}, {
loader: 'sass-loader',
options: {
includePaths: [],
sourceMap: true,
data: '$theme: light;',
},
},
],
}))
),
}
]
};
....
config.plugins.push(extractDark, extractLight);
Finally, my stylesheets have code like this:
$backgroundcolor: white;
@if $theme == dark {
$backgroundcolor: black;
}
.myClass {
background-color: $backgroundcolor;
}