Skip to content
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

All output files register changes with any file change while watching #7

Open
jacksonStone opened this issue Sep 25, 2019 · 3 comments · May be fixed by #12
Open

All output files register changes with any file change while watching #7

jacksonStone opened this issue Sep 25, 2019 · 3 comments · May be fixed by #12

Comments

@jacksonStone
Copy link

When we use this plugin while running a webpack watch, with many output/entry files, all of these files are registering changes if any file has a change. Since most of the file source is cached for rebuilding the output files, output file construction does not seem to take long, but with sourcemaps enabled, all sourcemaps are also rebuilding, taking a lot of time.

This amounts to a watcher change taking close to the same amount of time as a whole webpack build for us.

Do you think there would be any way to add watcher support for this plugin such that it does not trigger changes to everything?

I've been poking around to see what's possible using the source of this project, but it seems if I check the chunk hash for changes and only run your logic on these, all the wrappers for other output files are removed.

Perhaps there is a different event hook that could be tapped into?

@levp levp closed this as completed in e1809b1 Oct 1, 2019
@levp
Copy link
Owner

levp commented Oct 1, 2019

@jacksonStone You're right, it does seem like the current implementation of this plugin causes all bundles to be rebuilt even when a change only affects one of them.

After some playing around it seems like the implementation should ignore chunks that have their rendered property set to true. I've tested the fix to the best of my abilities and currently marked it as 2.2.0-beta.0. Please let me know if this solves the issue and I'll mark it as a stable release.

npm i -D [email protected]

@levp levp reopened this Oct 1, 2019
@jacksonStone
Copy link
Author

jacksonStone commented Oct 7, 2019

Had a chance to give it a whirl. It seems to only rebuild the source file that had changes, however, all source files not built have the wrapper removed, and all sourcemaps are still being constructed.

@marcins
Copy link

marcins commented Aug 24, 2020

Just ran into this as well, however I have some more input - Webpack's emit code keeps a cache based on the Source object identity rather than content:

https://github.com/webpack/webpack/blob/542ffa969d2f4c67c309ff711ccf00b27ace9ee5/lib/Compiler.js#L546-L554

This plugin creates a new Source object every time here:

compilation.assets[fileName] = new ConcatSource(
String(headerContent),
compilation.assets[fileName],
String(footerContent),
);
which means that cache is never valid on subsequent passes.

I haven't looked too deeply into it yet, but adding a cache to the plugin instance using the header/footer + original source object as a key, and returning the previous object if there's a match should avoid these re-emits.

(For reference - for our very large web application re-emit on a no-op change to a source file takes about 10s in watch mode, so cutting this down would be a significant win for us)

marcins added a commit to marcins/wrapper-webpack-plugin that referenced this issue Aug 25, 2020
This change implements a cache for Sources generated by this plugin
so that on subsequent builds (i.e. incremental builds) we can re-use
the same Source if the content hasn't changed.

This improves performance with Webpack's `futureEmitAssets` mode, where
there is a cache based on Source referential identity that determines
whether an asset should be re-emitted.

Fixes levp#7
@marcins marcins linked a pull request Aug 25, 2020 that will close this issue
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 a pull request may close this issue.

3 participants