Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use correct stage for adding assets during compilation #1286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -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
@@ -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
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the significance of the specified stage @JonWallsten?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"add additional assets to the compilation." I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the preferred way of doing it in Webpack 5. @alexander-akait metioned it in the beginning of the big PR. It shouldn't affect anything at all. It's just more future proof.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it is right usage, we can implement cache here in future

},
() => {
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