New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
splitChunks can create initial chunks that are empty after CSS extraction #7300
Comments
@edmorley Maybe related webpack-contrib/mini-css-extract-plugin#85? |
Hi! I saw that issue before filing this, however in that issue a custom |
Yep that's true |
Another issue that this causes, is that the empty (plus also "not quite empty, but still less than the 30KB minimum size") chunks use up the This has the knock on effect of slower builds , since there is more to minify/source-map. (In one of my projects raising |
@sokra Is there any workaround for this issue you can think of? I'm simply trying to split out all vendor css, but this is creating an "empty" (file contents: |
@jpdesigndev try prepending those files' contents into you main entry manually. |
Any news on this? I think this is the final blocker for our upgrade to Webpack 4. |
This is blocking me to upgrade to webpack 4, but it is planned for webpack 5. I guess I will stop trying to upgrade until 5 comes out. |
The milestone for this used to be webpack 4.x, but has recently been changed to webpack 5. Was this due to the fix for this being seen as a breaking change, or because of timeframe/resources required to fix? |
Yes, it is breaking change |
hmm... maybe there is a way we could add it for webpack 4 too |
If this needs help, I'm happy to help out |
Seems like related to webpack-contrib/mini-css-extract-plugin#151 |
/cc @sokra will be great solve this for |
Right now I'm using this "workaround":
It's very specific for my use case and has things hardcoded and I even have just put it directly in the webpack.config.js file (so not published on npm). So it would be awesome if this could be fixed at webpack level. |
@sokra will this still be fixed in 4? We are migrating to 4 currently and everything works except this "empty" file. Or wait for 5 with css-webpack-plugin ? Awesome work by the way, i only had problems with the optimise part! |
@danechitoaie 's "workaround" worked for me, but it does unnecessary looping, incurs a dependency in class MiniCssExtractPluginCleanup {
constructor(deleteWhere = /\.js(\.map)?$/) {
this.shouldDelete = new RegExp(deleteWhere)
}
apply(compiler) {
compiler.hooks.emit.tapAsync("MiniCssExtractPluginCleanup", (compilation, callback) => {
Object.keys(compilation.assets).forEach((asset) => {
if (this.shouldDelete.test(asset)) {
delete compilation.assets[asset]
}
})
callback()
})
}
} Which then in their case could be used by passing in the RegExp module.exports = {
...,
plugins: [
new MiniCssExtractPluginCleanUp(),
],
...,
} |
Also remember you can just run console command to delete / modify this files after webpack done his job.
Can be useful: Pre and Post hooks for npm scripting |
@Kajeczko in some cases this file can have code that run webpack. Example:
|
@usebaz that kind of code isn't necessary to use the css files, and are safe to delete. |
Partial solved in webpack@5: {
optimization: {
splitChunks: {
cacheGroups: {
styles: {
type: 'css/mini-extract',
chunks: 'all',
// If you need this uncomment
// enforce: true,
},
},
},
},
} |
#11585 should fix it, I will put couple tests in mini-css-extract-plugin to ensure all works fine |
@evilebottnawi I've tried with the following packages and this config
but it still outputs a |
@martinherweg Please create reproducible test repo, I think you still on old webpack |
@evilebottnawi https://github.com/martinherweg/webpack-css-chunks here I've created a very small test repo. |
@martinherweg to be honestly it is not related to this issue, we create empty js because you need js entrypoint, but because you don't have js it is just empty, it's a bit like this problem, but it's a different problem, can you open a new issue about this? |
@evilebottnawi just to confirm my understanding. For which cases is your fix where it doesn't generate an empty JS file? I've added an additional entry point with a JS file, still it generates an empty JS file for the CSS only entry. I understand it's not related to that issue, I just read various threads about this and read your comment here that it's fixed. Do you think it's webpack or mini-css-extract-plugin related? Thanks. |
For all cases, except non js entry points
webpack |
So there still isn't a fix for this? |
Partial fixed |
I created a plugin to fix this for us and hold us over until webpack 5. Works fine after the webpack 5 upgrade, but this plugin did the job until then: https://github.com/michaeldurfey/fix-style-emits-webpack-plugin Just concats the empty js files onto the main entrypoint js. |
Still not fixed for me when using webpack 5:
Produces the following js file: |
@meglio Not all chunks can be dropped, please create reproducible test repo, I will look |
@alexander-akait , I've been playing with various options and made the following discovery: Using Removing that and using Does this make any sense, and is there an explanation of this behaviour? |
|
Is there any way to contribute to docs without running a full local developer copy of the webpack website? |
You can send improve here https://github.com/webpack-contrib/mini-css-extract-plugin |
Do you suggest adding a note in this section? |
Thanks @toastal for your minimal plugin, it does the job! |
Bug report
What is the current behavior?
The
splitChunks
feature (usingchunks: 'all'
) doesn't take into account CSS extraction (viamini-css-extract-plugin
) when deciding whether to create a new inital chunk. A new chunk can end up being created that is empty (other than the webpack functions) and under the default 30KBsplitChunks.minSize
threshold so shouldn't have been created.eg:
dist/vendors~pageA~pageB.js
For webpack build log output see:
https://github.com/edmorley/testcase-webpack-splitchunks-css#actual
If the current behavior is a bug, please provide the steps to reproduce.
git clone https://github.com/edmorley/testcase-webpack-splitchunks-css.git
yarn install
yarn build
What is the expected behavior?
There is no
dist/vendors~pageA~pageB.js
chunk generated, since after the CSS is extracted, there should be no common JS code between the two pages.Other relevant information:
webpack version: 4.8.3
Node.js version: 10.1.0
Operating System: Windows 10
Additional tools: mini-css-extract-plugin@0.4.0
The text was updated successfully, but these errors were encountered: