Skip to content

Commit cf07d58

Browse files
πŸ› Fix chunk optimization listeners (#35)
* 🎨 Cleanup code + fix deprecation warning * 🎨 Remove more legacy code + fix stage * 🎨 Remove previous hook * 🎨 Fix requested changes * πŸ› Fix chunk optimization
1 parent 70229d1 commit cf07d58

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

β€Žsrc/webpack/CompilerEventsFacade.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Compilation, Compiler } from "webpack";
1+
import { Chunk, Compilation, Compiler } from "webpack";
22

33
export default class CompilerEventsFacade {
44
public static extensionName = "webpack-extension-reloader";
@@ -15,16 +15,21 @@ export default class CompilerEventsFacade {
1515
return this._compiler.hooks.compilation.tap(
1616
CompilerEventsFacade.extensionName,
1717
(comp) => {
18-
const afterOptimizeChunkAssets = (chunks) => {
19-
call(comp, chunks);
18+
const chunks = new Set();
19+
const afterOptimizeChunkAssets = (chunksAfterOptimization) => {
20+
call(comp, chunksAfterOptimization);
2021
};
21-
/* https://github.com/webpack/webpack/blob/main/lib/Compilation.js#L772-L779
22-
afterOptimizeChunkAssets = PROCESS_ASSETS_STAGE_OPTIMIZE + 1
23-
*/
24-
const stage = Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + 1;
25-
(comp.hooks as any).processAssets.tap(
26-
{ name: CompilerEventsFacade.extensionName, stage },
27-
afterOptimizeChunkAssets,
22+
comp.hooks.processAssets.tap(
23+
{
24+
name: CompilerEventsFacade.extensionName,
25+
stage: Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
26+
},
27+
() => {
28+
comp.chunks.forEach((chunk) => {
29+
chunks.add(chunk);
30+
});
31+
afterOptimizeChunkAssets(chunks);
32+
},
2833
);
2934
},
3035
);

0 commit comments

Comments
Β (0)