Skip to content

Commit

Permalink
fix: Use correct stage for adding assets during compilation (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonWallsten authored Apr 20, 2021
1 parent b6c2e77 commit 5e08d5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v9.0.1

* [Use correct hook for emitting additional assets during compilation](https://github.com/TypeStrong/ts-loader/pull/1286) - thanks @jonwallsten

## v9.0.0

Breaking changes:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-loader",
"version": "9.0.0",
"version": "9.0.1",
"description": "TypeScript loader for webpack",
"main": "index.js",
"types": "dist",
Expand Down
18 changes: 10 additions & 8 deletions src/instances.ts
Original file line number Diff line number Diff line change
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 5e08d5d

Please sign in to comment.