Aaronius
Aaronius

Reputation: 4953

How can I get Webpack to resolve my loader

I'm writing a Webpack loader and am trying to figure out how to get Webpack to "recognize" it after I've npm-installed the loader as a dependency. My loader is called turbine-loader and it's within an npm scope @reactor, therefore the package can be found in node_modules/@reactor/turbine-loader.

When I do require('turbine-loader!../myFile'); from a module and then run webpack I get:

Module not found: Error: Cannot resolve module 'turbine-loader' in ...

If, in addition to the above, I put this in my webpack config:

resolveLoader: {
  alias: {
    'turbine-loader': require.resolve('@reactor/turbine-loader')
  }
}

It starts to work, but I don't want to force my loader consumers to do that if I don't need to. Could someone point me in the right direction? Maybe translate some Webpack docs into plain English for me? Thanks!

Upvotes: 2

Views: 110

Answers (1)

Alexandr Subbotin
Alexandr Subbotin

Reputation: 1734

Webpack just tries to require your loader by name. So if you try require('turbine-loader!../myFile'); it will require('turbine-loader'), that is not defined.

Instead, you have to add your scope name to this require statement: require('@reactor/turbine-loader!../myFile');.

Btw, for me it looks pretty ugly and I'd prefer your option with alias:)

Upvotes: 1

Related Questions