webpack-contrib / transform-loader

transform loader for webpack
MIT License
110 stars 23 forks source link

add index options #33

Closed MrKou47 closed 6 years ago

MrKou47 commented 6 years ago

This PR contains a:

Motivation / Use-Case

Use webpack.LoaderOptionsPlugin may not be a good idea.

Because webpack.LoaderOptionsPlugin may change the loader's context.For example, when i use css-loader to generate css-module code, at this time loader-utils will use this.context to generate style's hash loader-utils#L265.So when i use webpack multi entries to build an universal-react app, This problem may lead to generate different css-hash(because i use transform-loader only in the client entry), it might be header__logo___1WE56 and header__logo__2USE

Breaking Changes

So we should use loader.options to avoid this problem. I add a new option index to assign the current transform, used like:

{
  loader: 'transform-loader',
  options: {
    index: 0,
    transforms: [
      function(file) {
        return brfs(file, { parserOpts: { allowImportExportEverywhere: true } });
      }
    ]
  }
}

Additional Info

It's just an idea, if you think it will be ok, i will update the README later.😃

jsf-clabot commented 6 years ago

CLA assistant check
All committers have signed the CLA.