Skip to content

Conversation

@rvlb
Copy link
Contributor

@rvlb rvlb commented Oct 26, 2025

No description provided.

@rvlb rvlb marked this pull request as draft October 26, 2025 02:44
@rvlb rvlb changed the title Draft: Add assetEmitted hook Add assetEmitted hook Oct 26, 2025
@rvlb rvlb self-assigned this Oct 26, 2025
@rvlb rvlb force-pushed the add-asset-emitted-hook branch from c77b83b to 2da54ab Compare October 29, 2025 13:22
@rvlb rvlb changed the title Add assetEmitted hook Change stats file assets are build using emit hook Oct 30, 2025
@rvlb rvlb marked this pull request as ready for review October 30, 2025 22:32
compiler.hooks.compile.tap(this.name, this._handleCompile.bind(this, compiler));
compiler.hooks.done.tap(this.name, this._handleDone.bind(this, compiler));
compiler.hooks.compile.tap(this.name, this._handleCompile.bind(this));
compiler.hooks.emit.tap(this.name, this._handleEmit.bind(this));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The emit hook was the only place where we could always access the full list of compiled assets and could access their in-memory contents.

Other hooks tried:

  1. done: we could not access the in-memory content of the files
  2. compilation.processAssets: we do not have to all compiled assets, broke tests where we compressed them
  3. assetEmitted: we have access to all files + their in-memory content, however it's not always called without changing the plugin settings, so ended up causing the stats file to have missing files when not used in a dev server environment.

@rvlb
Copy link
Contributor Author

rvlb commented Oct 30, 2025

This update was also tested using the examples from django-webpack-loader, with and without setting integrity: true in the plugin parameters.

@rvlb rvlb requested a review from fjsj October 30, 2025 22:38
@rvlb rvlb changed the title Change stats file assets are build using emit hook Change how stats file assets are build using emit hook Oct 31, 2025
);
});

it('It should generate the stats file when the plugin runs twice and the output assets already exist', done => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test ensures that even if an asset didn't change between builds, the stats file will always contain its correct info.

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.

2 participants