Skip to content

Commit d45e452

Browse files
committed
fix: Use correct stage for adding assets during compilation
1 parent b6c2e77 commit d45e452

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/instances.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,16 @@ function addAssetHooks(loader: WebpackLoaderContext, instance: TSInstance) {
314314
);
315315

316316
const makeAssetsCallback = (compilation: webpack.Compilation) => {
317-
compilation.hooks.afterProcessAssets.tap('ts-loader', () =>
318-
cachedMakeAfterCompile(compilation, () => {
319-
return null;
320-
})
317+
compilation.hooks.processAssets.tap(
318+
{
319+
name: 'ts-loader',
320+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
321+
},
322+
(_assets) => {
323+
cachedMakeAfterCompile(compilation, () => {
324+
return null;
325+
});
326+
}
321327
);
322328
};
323329

@@ -327,10 +333,6 @@ function addAssetHooks(loader: WebpackLoaderContext, instance: TSInstance) {
327333

328334
// For future calls in watch mode we need to watch for a new compilation and add the hook
329335
loader._compiler.hooks.compilation.tap('ts-loader', makeAssetsCallback);
330-
331-
// It may be better to add assets at the processAssets stage (https://webpack.js.org/api/compilation-hooks/#processassets)
332-
// This requires Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, which does not exist in webpack4
333-
// Consider changing this when ts-loader is built using webpack5
334336
}
335337

336338
export function initializeInstance(

0 commit comments

Comments
 (0)