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

后端 未结 2 1985
后悔当初
后悔当初 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"
            ]
          }
        ]
      }
    

提交回复
热议问题