Description
- Operating System: Mac OS 10.14.5
- Node Version: v8
- NPM Version: v5
- webpack Version: v4
- mini-css-extract-plugin Version: v0.8.0
Feature Proposal
Support multiple instances of MiniCssExtractPlugin to generate multiple themed CSS outputs from the shared singular CSS/SCSS input.
Sample code
const __home = path.resolve(__dirname, '');
module.exports = {
entry: path.resolve('src/index.js'),
output: {
filename: "[name].js",
path: path.resolve("dist")
},
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "sass-loader",
options: { includePaths: [path.resolve(__home, "src/light-theme"),]}
}
]
// Want to do something like this to generate a second CSS theme bundle based on the shared CSS input extracted from the JS
// use: [
// MiniCssExtractPlugin.loader,
// "css-loader",
// {
// loader: "sass-loader",
// options: { includePaths: [path.resolve(__home, "src/dark-theme"),]}
//
// }
// ]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "light-theme.css"
})
// new MiniCssExtractPlugin({
// filename: "dark-theme.css"
// })
]
};
Feature Use Case
The use-case for this is an app that wants to support both a dark and light mode styles without having to rely on CSS-in-JS solutions. Instead, it would be nice to extract the CSS from the common singular source CSS and output that into 2 separate stylesheets which use different SCSS variables to generate the dark and light variants of the stylesheet.
This seems feasible if multiple instances of MiniCssExtractPlugin were supported:
One that applies the light-mode theme variables via the configured sass-loader in the first mini-css-extract configuration.
And a second instance that applies the dark-mode theme variables via the configured sass-loader in the second mini-css-extract configuration.
If there is another way to achieve this, I'd be very interested.