Skip to content

Commit

Permalink
fix: Use correct stage for adding assets during compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
JonWallsten committed Apr 19, 2021
1 parent b6c2e77 commit 4f766ed
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/instances.ts
Expand Up @@ -314,10 +314,16 @@ function addAssetHooks(loader: WebpackLoaderContext, instance: TSInstance) {
);

const makeAssetsCallback = (compilation: webpack.Compilation) => {
compilation.hooks.afterProcessAssets.tap('ts-loader', () =>
cachedMakeAfterCompile(compilation, () => {
return null;
})
compilation.hooks.processAssets.tap(
{
name: 'ts-loader',
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
},
() => {
cachedMakeAfterCompile(compilation, () => {
return null;
});
}
);
};

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

// For future calls in watch mode we need to watch for a new compilation and add the hook
loader._compiler.hooks.compilation.tap('ts-loader', makeAssetsCallback);

// It may be better to add assets at the processAssets stage (https://webpack.js.org/api/compilation-hooks/#processassets)
// This requires Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, which does not exist in webpack4
// Consider changing this when ts-loader is built using webpack5
}

export function initializeInstance(
Expand Down

0 comments on commit 4f766ed

Please sign in to comment.