-
-
Notifications
You must be signed in to change notification settings - Fork 388
Description
Bug report
MiniCssExtractPlugin does not work in cross-package compilation setting
Context:
When configuring a monorepo for parallel compilation (https://webpack.js.org/configuration/configuration-types/#parallelism) I noticed that MiniCssExtractPlugin does not work when more than 1 configuration has MiniCssExtractPlugin as a plugin.
I suggest, that src/index.js:206 which now looks like this:
webpack.util.serialization.register(CssModule, "mini-css-extract-plugin/dist/CssModule", null...
to be changed to something like this:
webpack.util.serialization.register(CssModule, "mini-css-extract-plugin/dist/CssModule", __dirname
or
webpack.util.serialization.register(CssModule, "mini-css-extract-plugin/dist/CssModule", Math.random()
1st one would prevent using the loader from the same node_modules twice and would enable using multiple MiniCssExtractPlugin accross multiple configurations (which is what I want)
2nd one would allow using MiniCssExtractPlugin multiple times without any restrictions
Actual Behavior
Webpack throws an error:
Error: ObjectMiddleware.register: serializer for mini-css-extract-plugin/dist/CssModule/null is already registered
Expected Behavior
Webpack should be able to compile multiple configurations with MiniCssExtractPlugin as a plugin
How Do We Reproduce?
Set up two packages, which use MiniCssExtractPlugin. It is important, that webpack configurations have proper loader resolution:
resolveLoader: { modules: [path.resolve(__dirname, 'node_modules'), 'node_modules'], }
Set up a third package, which as a webpack.config.js exports configurations of previous 2 packages.
Run webpack in the third package. It throws the error I described.
If we agree on a solution I'd more than happy to submit a PR