Skip to content

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

Description

@jacksonStone

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?

Activity

  1. levp commented on Oct 1, 2019

    @levp
    Owner

    @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 wrapper-webpack-plugin@2.2.0-beta.0

  2. reopened this on Oct 1, 2019
  3. jacksonStone commented on Oct 7, 2019

    @jacksonStone
    Author

    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.

  4. marcins commented on Aug 24, 2020

    @marcins

    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)

  5. added a commit that references this issue on Aug 25, 2020
    421a924
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions