Skip to content

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

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

fix: Use correct stage for adding assets during compilation#1286
johnnyreilly merged 1 commit into
TypeStrong: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!

Comment thread src/instances.ts
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?

@JonWallsten JonWallsten Apr 20, 2021

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

johnnyreilly commented Apr 20, 2021

Copy link
Copy Markdown
Member

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