Closed
Description
The extract-webpack-text-plugin allows you to define multiple instances of the plugin. Does MiniCssExtractPlugin support the same feature? My end goal is to generate multiple bundles for SASS themes.
The extract-webpack-text-plugin allows you to define multiple instances of the plugin. Does MiniCssExtractPlugin support the same feature? My end goal is to generate multiple bundles for SASS themes.
Activity
michael-ciniawsky commentedon Mar 20, 2018
Please describe your use case and provide your config, this might not be needed anymore with
mini-css-extract-plugin
james-s-turner commentedon Mar 20, 2018
Hi @michael-ciniawsky - thanks for the prompt response. Hopefully this will clarify the need.
I want to create an app with multiple themes - defined as SASS variables.
When the build runs, a CSS bundle file for each theme is emitted. Each component imports the SASS file containing the theme variables
@import "theme-vars.scss"
. I configure theincludePath
of thesass-loader
to point to the appropriate theme directory.The full setup is shown in the repository
The above config runs happily emitting the css bundle
/dist/light-theme.css
. I can change theincludePaths
variable and generate/dist/dark-theme.css
.I want to run the build once - emitting both light and dark theme bundles.
So as shown in the putative commented out code, I want to somehow create "two instances" of the MiniCssExtractPlugin. Each one configured with the appropriate theme directory path.
alexkrolick commentedon Mar 20, 2018
Another use case is this:
In ETWP we'd do:
albertstill commentedon Mar 21, 2018
Here is an example repo of me trying to achieve theming with multiple instances of
extract-text-webpack-plugin
and two seperate PostCSS configs. It compiles but no files are written to disk, be great if this library supported the use case!garygreen commentedon Mar 27, 2018
Does this functionality not overlap with
splitChunks
? Your essentially wanting to split your different theme files? Seems to me you can just split your rules up so they generate each theme separately and use splitChunks to output them into the correct files?james-s-turner commentedon Mar 27, 2018
@garygreen I can't see how that would work. In the end the SASS processor has to run twice (with different variables files each time) generating parallel sets of CSS. My understanding off chunks is that it's one set of output split into different bits - rather than two separate outputs. I'd happily be proved wrong tho ;-)
garygreen commentedon Mar 27, 2018
@james-s-turner I'm thinking something along the lines of:
With a splitChunks section etc.
Or is that just a slightly different way to write what your trying to achieve?
sokra commentedon Mar 29, 2018
Interesting use case. The same could be supported for the mini-css-extract-plugin. In the same way as it's implemented in extract-text-webpack-plugin.
Send a PR.
james-s-turner commentedon Mar 30, 2018
@garygreen Unfortunately if you define two rules with the same test pattern - then only the first one is run
ccorcos commentedon Apr 12, 2018
@michael-ciniawsky the goal is just to be able to create more than one CSS file. Any suggestions?
lukepolo commentedon Apr 19, 2018
We also have something like this where we have our
sass
styles getting extracted, then wanting to extract ourvue
styles to a different file.57 remaining items