mini-css-extract-plugin: adding splitChunks all is breaking the module exports
- Operating System: macOS mojave
- Node Version: v11.3.0
- NPM Version: 6.7.0
- webpack Version: 4.33.0
- mini-css-extract-plugin Version: 0.7.0
Expected Behavior
Having concatenated all CSS in the file should not break the module exports.
Actual Behavior
Adding the splitChunks optimization for a single css file is breaking the umd build exports.
Code
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true,
},
},
},
},
How Do We Reproduce?
- create with umd build as output and configure the optimization rule and try and importing the component from the library. it fails with error
TypeError: Cannot read property <functionName> of undefined
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 10
- Comments: 29 (9 by maintainers)
Guys, I dont know a root problem, but I make this thing works for me. splitChunks all generates two files. 1 -
styles.css
itself. 2-styles.js
file with empty css files modules And the problem is - thisstyles.js
file is not used in main bundle fileindex.js
so in my html file
was
now
with
AutomaticPrefetchPlugin
for makes this work before main bundleAfter more digging, it looks like the extra JS file produced might be the cause?. Something isn’t getting executed.
1.index.js:
When this file gets generated, the main js file has different code generated:
Good:
Bad:
Has someone been able to fix this problem? I got the same issue with Webpack 4 where I activate splitChunks and get undefined for my imports.
setting the splitchunks.cacheGroups.[chunkname].name=‘main’ solves the problem with additional little file.
@kalbert312 it is in my todo list, look on this in near future (today/tomorrow)
Should be solved, only one problem is empty JS files, but it should be fixed in webpack itself https://github.com/webpack/webpack/issues/11671, if anybody will faced the the problem feel free to feedback and I will help
What about this https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free?