Skip to content

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

Closed
wants to merge 11 commits into from
Closed

Remove empty modules #380

wants to merge 11 commits into from

Conversation

irudoy
Copy link
Contributor

@irudoy irudoy commented Apr 18, 2019

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

fixes #357

Breaking Changes

Additional Info

@jsf-clabot
Copy link

jsf-clabot commented Apr 18, 2019

CLA assistant check
All committers have signed the CLA.

@alexander-akait
Copy link
Member

Please fix CI problems, also accept CLA, thanks

@irudoy
Copy link
Contributor Author

irudoy commented Apr 18, 2019

@evilebottnawi do you suggest updating vulnerable dependencies in this PR?
CLA has already been signed.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job 👍

@irudoy
Copy link
Contributor Author

irudoy commented Apr 29, 2019

Friendly ping

@alexander-akait
Copy link
Member

All looks very good, wait @sokra review (we do this in near future), thanks fro waiting

@aberezkin
Copy link

@sokra, @evilebottnawi, any news about that?

@codecov
Copy link

codecov bot commented May 29, 2019

Codecov Report

Merging #380 into master will increase coverage by 0.78%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/index.js 89.30% <100.00%> (+1.44%) ⬆️
src/loader.js 89.47% <100.00%> (+0.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ffc393...396cba7. Read the comment docs.

@irudoy
Copy link
Contributor Author

irudoy commented Jun 19, 2019

Any news?

@irudoy
Copy link
Contributor Author

irudoy commented Aug 4, 2019

@sokra @evilebottnawi is it ok now?

@irudoy irudoy requested a review from sokra September 18, 2019 11:26
@irudoy
Copy link
Contributor Author

irudoy commented Sep 23, 2019

Any news?

Copy link
Member

@sokra sokra left a 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) => {
Copy link
Member

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);
Copy link
Member

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.

@alexander-akait
Copy link
Member

/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

@igoradamenko
Copy link

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?

@irudoy
Copy link
Contributor Author

irudoy commented Oct 31, 2019

@igoradamenko as @sokra noted we should implement it using finishModules hook. Unfortunately, I haven't much time at the moment to do this. I will try to finish it soon.

@therealshark
Copy link

@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 :)

@kherock
Copy link

kherock commented Mar 27, 2020

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:
Remove empty CSS modules workaround

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.

@irudoy
Copy link
Contributor Author

irudoy commented Mar 27, 2020

@kherock thanks for the contribution!

@sokra @evilebottnawi
As of webpack-5-beta.13, the problem still exists. Dead code with empty modules remains in the production bundle. Maybe it is possible to remove it at the webpack level? If there is no code in the module (excluding comments), remove the module automatically.

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.

@ScriptedAlchemy
Copy link
Contributor

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.

@irudoy
Copy link
Contributor Author

irudoy commented Aug 10, 2020

Seems like it was fixed by #546 (using esModule: true option)

Can we close this PR and related issue?

@alexander-akait
Copy link
Member

Yes, let's add more tests, WIP

@irudoy
Copy link
Contributor Author

irudoy commented Aug 11, 2020

@evilebottnawi with another PR, maybe?

@alexander-akait
Copy link
Member

@irudoy yes, we can do it in the separate PR

@irudoy irudoy closed this Aug 11, 2020
@irudoy
Copy link
Contributor Author

irudoy commented Aug 13, 2020

@evilebottnawi done #566

@aleen42
Copy link

aleen42 commented Apr 8, 2022

I have tested with {esModule: true}, which is true by default, and found that there were still so many empty modules:

(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?");

/***/ }),

    // ...
}]);

@alexander-akait
Copy link
Member

Because you import them in JS, we can't fully remove them, otherwise if will get wrong behavior

@aleen42
Copy link

aleen42 commented Apr 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Optimization request] Remove empty "modules"