Skip to content

Webpack 5 LoaderContext: addContextDependency causes loader to rerun once after any change in watch mode #16886

@modjke

Description

@modjke

Our project relies heavily on custom 'heavy' loaders, and fast compilation is crucial. In watch mode, every loader that utilizes addContextDependency reruns one more time after any project change, leading to longer build times. Trying to find a solution to minimize the re-running of these loaders and improve watch mode performance.

Bug report

After initial compilation in watch mode every loader that uses addContextDependency will rerun one more time after any change in the project.

What is the current behavior?

Custom loaders that use addContextDependency will rerun only if supplied context dependencies are changed.

If the current behavior is a bug, please provide the steps to reproduce.

Reproducible example here:
https://github.com/modjke/webpack-5-add-context-dependency-issue
txt-loader.js will run twice: at startup and for the first time index.js is changed

What is the expected behavior?

Loaders with addContextDependency should run only once on initial compilation in watch mode.

What have we tried?

  • debugging watchpack, as it turns out watchpack reports changes correctly
  • using async/sync loaders (same bug appears)
  • increasing aggregateTimeout
  • disabling hot module reload

Other relevant information:

webpack version: 5.76.3
Node.js version: 18.15.0
Operating System: Mac OS (M1), Windows 11 H22, Windows 10
Additional tools: ~

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions