loader-utils icon indicating copy to clipboard operation
loader-utils copied to clipboard

Missing getOptions.js in lib ?

Open hawenger opened this issue 3 years ago • 5 comments

Related to TypeError: this.getOptions is not a function

hawenger avatar Jan 31 '22 18:01 hawenger

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

alexander-akait avatar Jan 31 '22 18:01 alexander-akait

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

andrralv avatar Feb 25 '22 22:02 andrralv

this.getOptions, this is loaderContext inside loader function

alexander-akait avatar Feb 26 '22 12:02 alexander-akait

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, '*')));
}

AddJunZ avatar Jan 04 '24 12:01 AddJunZ

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

alexander-akait avatar Jan 04 '24 12:01 alexander-akait