Skip to content

Commit

Permalink
πŸ› Fix chunk optimization listeners (#35)
Browse files Browse the repository at this point in the history
* 🎨 Cleanup code + fix deprecation warning

* 🎨 Remove more legacy code + fix stage

* 🎨 Remove previous hook

* 🎨 Fix requested changes

* πŸ› Fix chunk optimization
  • Loading branch information
legitatx authored Jul 15, 2021
1 parent 70229d1 commit cf07d58
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/webpack/CompilerEventsFacade.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compilation, Compiler } from "webpack";
import { Chunk, Compilation, Compiler } from "webpack";

export default class CompilerEventsFacade {
public static extensionName = "webpack-extension-reloader";
Expand All @@ -15,16 +15,21 @@ export default class CompilerEventsFacade {
return this._compiler.hooks.compilation.tap(
CompilerEventsFacade.extensionName,
(comp) => {
const afterOptimizeChunkAssets = (chunks) => {
call(comp, chunks);
const chunks = new Set();
const afterOptimizeChunkAssets = (chunksAfterOptimization) => {
call(comp, chunksAfterOptimization);
};
/* https://github.com/webpack/webpack/blob/main/lib/Compilation.js#L772-L779
afterOptimizeChunkAssets = PROCESS_ASSETS_STAGE_OPTIMIZE + 1
*/
const stage = Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + 1;
(comp.hooks as any).processAssets.tap(
{ name: CompilerEventsFacade.extensionName, stage },
afterOptimizeChunkAssets,
comp.hooks.processAssets.tap(
{
name: CompilerEventsFacade.extensionName,
stage: Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
},
() => {
comp.chunks.forEach((chunk) => {
chunks.add(chunk);
});
afterOptimizeChunkAssets(chunks);
},
);
},
);
Expand Down

0 comments on commit cf07d58

Please sign in to comment.