S
S
shasoft2021-04-05 23:01:31
webpack
shasoft, 2021-04-05 23:01:31

How to change module type in webpack loader?

I have a json file that outputs a javascript code as output. But this webpack code is still trying to process as JSON and getting an error. How can I change the type of the module to javascript so that in the future it will be processed as js?

ps Found this option, but it does not work in Version 5

const requiredType = 'javascript/auto';
    const factory = this._compilation.dependencyFactories.get(LoaderDependency);
  console.log('factory',factory);
    this._module.type = requiredType;
    this._module.generator = factory.getGenerator(requiredType);
    this._module.parser = factory.getParser(requiredType);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question