-
-
Notifications
You must be signed in to change notification settings - Fork 384
Remove empty modules #380
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
Remove empty modules #380
Conversation
Please fix CI problems, also accept CLA, thanks |
@evilebottnawi do you suggest updating vulnerable dependencies in this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job 👍
Friendly ping |
All looks very good, wait @sokra review (we do this in near future), thanks fro waiting |
@sokra, @evilebottnawi, any news about that? |
Codecov Report
@@ Coverage Diff @@
## master #380 +/- ##
==========================================
+ Coverage 88.49% 89.27% +0.78%
==========================================
Files 5 5
Lines 426 457 +31
Branches 94 104 +10
==========================================
+ Hits 377 408 +31
Misses 47 47
Partials 2 2
Continue to review full report at Codecov.
|
Any news? |
@sokra @evilebottnawi is it ok now? |
Any news? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved a lot since last review 👍
@@ -390,6 +399,47 @@ class MiniCssExtractPlugin { | |||
return source; | |||
} | |||
); | |||
|
|||
compilation.hooks.optimizeChunks.tap(pluginName, (chunks) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done earlier, maybe in finishModules
. Otherwise unneeded things are done for these removed modules, i. e. added to chunks, assigned ids, etc.
cssModuleReason.module && | ||
cssModuleReason.module.buildMeta.extracted | ||
) { | ||
chunk.removeModule(cssModuleReason.module); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be unneeded when using finishModules
hook.
/cc @irudoy you do great job, big thanks, ping me when you need review or help from me or sokra We do release after merge this |
Hey guys! What is the status of the PR? Is it going to be merged? I see that @irudoy has already pushed some changes. Are they enough to merge or not? May I help to speed up the development here in any way? |
@igoradamenko as @sokra noted we should implement it using |
@irudoy Did you have any time to work on this? The Project i'm working on currently has ~640 empty modules because of this behaviour, so this pr would help us quite a bit :) |
For those following this issue that still can't use webpack 5 for one reason or another - I've created a gist that contains the most complete implementation of a plugin for removing empty JS files that I'm aware of: The implementation is mostly inspired by the work in this PR plus some of the suggested changes. Some of the issues I ran into with other workarounds posted is that they break with split chunks or have other quirks when optimization is enabled. |
@kherock thanks for the contribution! @sokra @evilebottnawi If this option is not suitable, maybe we have a new and more proper way to remove unnecessary modules in webpack-5? Or maybe we need the new API as of webpack-5, which will allow us to easily remove unneeded modules? The current implementation looks fragile and brings an overhead that seems to be avoided by doing so in the webpack core. |
if someone has something stable, ill be willing to accept a PR to extract-css-chunks-webpack-plugin. Its got a decent amount of users and I regularly try to PR changes from extract-css back to mini-css. Serves as a good testing ground as well. So if anyone wants something installable on NPM, open a PR there and as long as its stable ill release it till this PR gets merged. |
Seems like it was fixed by #546 (using Can we close this PR and related issue? |
Yes, let's add more tests, WIP |
@evilebottnawi with another PR, maybe? |
@irudoy yes, we can do it in the separate PR |
@evilebottnawi done #566 |
I have tested with (self["webpackJsonp"] = self["webpackJsonp"] || []).push([["X"],{
// ...
/***/ "./a.less":
/*!***************************************************************************************************************!*\
!*** ./a.less ***!
\***************************************************************************************************************/
/***/ (function() {
eval("// extracted by mini-css-extract-plugin\n\n//# sourceURL=webpack://cmxt.wmweb/./a.less?");
/***/ }),
/***/ "./b.less":
/*!***************************************************************************************************!*\
!*** ./b.less ***!
\***************************************************************************************************/
/***/ (function() {
eval("// extracted by mini-css-extract-plugin\n\n//# sourceURL=webpack://cmxt.wmweb/./b.less?");
/***/ }),
// ...
}]); |
Because you import them in JS, we can't fully remove them, otherwise if will get wrong behavior |
The hardest thing to remove is to eliminate all import points in JavaScript, but it should be a feature to do so. |
This PR contains a:
Motivation / Use-Case
fixes #357
Breaking Changes
Additional Info