When do I use 'use' and 'loader' in Webpack 2 module.rules?

后端 未结 2 1987
后悔当初
后悔当初 2021-02-06 21:59

I am upgrading my current project to Webpack2, which it was using Webpack1 prior. I have looked into a couple tutorials about upgrading and in

相关标签:
2条回答
  • 2021-02-06 22:10

    As the Webpack 2 migration tutorial states, the difference between both is, that if when we want an array of loaders, we have to use use, if it's just one loader, then we have to use loader:

    module: {
       rules: [
          {
            test: /\.jsx$/,
            loader: "babel-loader", // Do not use "use" here
            options: {
              // ...
            }
          },
          {
            test: /\.less$/,
            loader: "style-loader!css-loader!less-loader"
            use: [
              "style-loader",
              "css-loader",
              "less-loader"
            ]
          }
        ]
      }
    
    0 讨论(0)
  • 2021-02-06 22:12

    module.rules is meant for loaders. Specifying a rule as loader is just a shortcut for

    use: [{loader}]
    

    For plugins, use the plugins property in your configuration.

    0 讨论(0)
提交回复
热议问题