Sam
Sam

Reputation: 30388

Converting webpack.config.js from 1.x to 2.x

The following is the modules section of my webpack.config.js file. I understand that loaders is now rules but how do I handle the query part?

This is the original 1.x version

module: {
   loaders: [
      {
         test: /\.jsx?$/,
         exclude: /(node_modules|bower_components)/,
         loader: 'babel',
         query: {
                  presets: ['es2015', 'stage-2', 'react']
         }
      }
   ]
}

Here's what I have so far for the 2.x version:

module: {
   rules: [
      {
         test: /\.jsx?$/,
         exclude: /(node_modules|bower_components)/,
         use: 'babel-loader',
         options: {
            // I assume we now use options. How do I handle the presets?
         }
      }
   ]
}

Upvotes: 1

Views: 29

Answers (1)

William Bernting
William Bernting

Reputation: 571

Correct Options usage for babel-loader

module: {
  rules: [
    {
      test: /\.jsx?$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: [
            "es2015",
            "react",
            "stage-2"
          ]
        }
      }
    }
  ]
}

I'd recommend either the above approach, or create a .babelrc file in your app root, with the below properties.

{
    "presets": [
        "es2015",
        "react",
        "stage-2"
    ]
}

Hope this helps.

Upvotes: 1

Related Questions