Skip to content

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

Merged
johnnyreilly merged 1 commit intoTypeStrong:mainfrom
JonWallsten:add-correct-compilation-hook
Apr 20, 2021
Merged

fix: Use correct stage for adding assets during compilation#1286
johnnyreilly merged 1 commit intoTypeStrong:mainfrom
JonWallsten:add-correct-compilation-hook

Conversation

@JonWallsten
Copy link
Copy Markdown
Contributor

No description provided.

@JonWallsten
Copy link
Copy Markdown
Contributor Author

@johnnyreilly: I extracted the fix from my previous webpack 5 branch and added on top of the v5. Seems to work fine!

compilation.hooks.processAssets.tap(
{
name: 'ts-loader',
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@JonWallsten JonWallsten Apr 20, 2021

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
Copy Markdown
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

@johnnyreilly
Copy link
Copy Markdown
Member

Cool - do you want to update the CHANGELOG.md and package.json ?

@JonWallsten
Copy link
Copy Markdown
Contributor Author

Cool - do you want to update the CHANGELOG.md and package.json ?

Done!

@johnnyreilly johnnyreilly merged commit 5e08d5d into TypeStrong:main Apr 20, 2021
@johnnyreilly
Copy link
Copy Markdown
Member

johnnyreilly commented Apr 20, 2021

Thanks!

https://github.com/TypeStrong/ts-loader/releases/tag/v9.0.1

@alexander-akait
Copy link
Copy Markdown
Contributor

@JonWallsten We can avoid using loader-utils https://github.com/TypeStrong/ts-loader/blob/main/src/index.ts#L2, it will be deprecated in near future:
https://github.com/TypeStrong/ts-loader/blob/main/src/index.ts#L177:

// No need fallback on `{}`, when not option it will be `{`}
const options = this.getOptions(schema); // schema is optional 

https://github.com/TypeStrong/ts-loader/blob/main/src/index.ts#L649, just change on:

loaderContext.remainingRequest

Because webpack v5 is minimum supported version, no breaking changes here, just less code and less deps

@JonWallsten JonWallsten deleted the add-correct-compilation-hook branch April 20, 2021 13:16
@johnnyreilly
Copy link
Copy Markdown
Member

Hey @alexander-akait

Are you saying that

  const loaderOptions =
    loaderUtils.getOptions<LoaderOptions>(loaderContext) ||
    ({} as LoaderOptions);

can become

const loaderOptions = this.getOptions(); // schema is optional 

?

@alexander-akait
Copy link
Copy Markdown
Contributor

Yes

@JonWallsten
Copy link
Copy Markdown
Contributor Author

I can do a PR if you'd like @johnnyreilly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants