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

Missing getOptions.js in lib ? #205

Open
hawenger opened this issue Jan 31, 2022 · 5 comments
Open

Missing getOptions.js in lib ? #205

hawenger opened this issue Jan 31, 2022 · 5 comments

Comments

@hawenger
Copy link

Related to TypeError: this.getOptions is not a function

@alexander-akait
Copy link
Member

geOptions was removed https://github.com/webpack/loader-utils/releases/tag/v3.0.0

removed getOptions in favor loaderContext.getOptions (loaderContext is this inside loader function), note - special query parameters like ?something=true is not supported anymore, if you need this please do it on loader side, but we strongly recommend avoid it, as alternative you can use ?something=1 and handle 1 as true

@andrralv
Copy link

@alexander-akait can we get a test/example on how to migrate getOptions to the new syntax?

@alexander-akait
Copy link
Member

this.getOptions, this is loaderContext inside loader function

@AddJunZ
Copy link

AddJunZ commented Jan 4, 2024

this.getOptions, this is loaderContext inside loader function this.getOptions

It really works for me. But I don't think it makes sense to just delete loaderUtils.getOptions(this).

module.exports = function cultureLoader(source) {
  // get loader options, replace const options = loaderUtils.getOptions(this);
  const options = this.getOptions();
  const { sensitiveWord } = options;
  var callback = this.async();
  callback(null, source.replace(sensitiveWord, ''.padEnd(sensitiveWord.length, '*')));
}

@alexander-akait
Copy link
Member

You should use this.getOptions instead loaderUtils.getOptions(this), now it is a part of webpack logic

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

No branches or pull requests

4 participants