2

I have used webpack ^2.2.1. I have added some loaders In my webpack.config.js file.

But my loader have not call in an order.

I used babel-loader for transform react-es6 codes to react-es5 codes. My custom-loader need react-es6 code. So I put my loader to first. I have print source content in each loaders. But every time first printing babel-loader info. After printing my info.

Is my loader order correct?

Help me! Thanks in advance!

   // webpack.config.js

    module.exports = {
      entry: './src/index.js',
      output: {
         filename: 'bundle.js',
         path: path.resolve(__dirname, './build')
      }
      module: {
         loaders: [
            {
                test: /\.js$/,
                use: 'my-custom-loader'
            },
            {
                test: /\.js$/,
                use: [
                   {
                      loader: 'babel-loader',
                      options: {
                         presets: ['babel-preset-es2015', 'babel-preset-react']
                      }
                   }
                ]
            }
         ]
      }
    }
Vasi Karan
  • 39
  • 3
  • Try declaring just one rule with multiple loaders. Right now, you have two rules that match the same pattern. Also, `module.loaders` has been replaced by [`module.rules`](https://webpack.js.org/guides/migrating/#module-loaders-is-now-module-rules) in Webpack 2. – robertklep Aug 18 '17 at 08:09
  • The loaders are used in order "right to left" so the last loader in your array is used first. See: https://stackoverflow.com/questions/32234329/what-is-the-loader-order-for-webpack – Flocke Aug 18 '17 at 08:52

1 Answers1

5

Loaders in Webpack are used in order "right to left" so the last loader in your array is used first. Therefore babel is translating everything and your loader is second in line.

See: What is the loader order for webpack?

Try switching the order of your loaders (and of course use module.rules instead of module.loaders, so that you are using the new Pattern in Webpack 2)

Flocke
  • 1,004
  • 17
  • 23