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

No longer possible to use different loader options for different files #1102

Closed
appzuka opened this issue May 7, 2020 · 5 comments
Closed
Labels

Comments

@appzuka
Copy link
Member

appzuka commented May 7, 2020

Expected Behaviour

It should be possible to specify different options for each file type in webpack.config:

module: {
rules: [
{ test: /.md$/, use: [{loader: "ts-loader", options: {logLevel: 'WARN', transpileOnly: true}}, "otherLoader"]},
{ test: /.ts$/, use: [{loader: "ts-loader", options: {logLevel: 'INFO', transpileOnly: false}}, "otherLoader"]}
]
}

Actual Behaviour

Since 7.0.0 this no longer works. successLoader in index.ts no longer accepts the options as a parameter so the loaderOptions will always be the options specified the first time ts_loader is invoked.

Steps to Reproduce the Problem

Create a webpack config which needs different options for different invocations of ts-loader

This could be fixed by adding a line to getTypeScriptInstance in instances.js:

function getTypeScriptInstance(loaderOptions, loader) {
if (instances.hasOwnProperty(loaderOptions.instance)) {
const instance = instances[loaderOptions.instance];
instance.loaderOptions = loaderOptions; // << Add this line

@johnnyreilly
Copy link
Member

Thanks for the detailed issue - that's very helpful! Would you like to submit a PR?

@appzuka
Copy link
Member Author

appzuka commented May 8, 2020

I have submitted a PR. The updated code passes the execution tests and also works in my application, which depends on this behaviour.

I note that the comparison tests don't work since 7.0.1.

@appzuka
Copy link
Member Author

appzuka commented May 10, 2020

I have generated a new pull request including an execution test.

While working on this I found that my previous patch was not sufficient if the changed options were functions (such as getCustomTransformers) as these are only attached when a new instance is created.

I also found that an option already exists to manage this behaviour, the 'instance' option. However, it is easy to miss that this is necessary so my new pull request automatically creates a new instance whenever the options change.

@stale
Copy link

stale bot commented Jul 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 11, 2020
@stale
Copy link

stale bot commented Jul 18, 2020

Closing as stale. Please reopen if you'd like to work on this further.

@stale stale bot closed this as completed Jul 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants