Babel 6 presets specified in .babelrc not working

as the name implies, mainly according to the docs, with the new Babel 6 we now have to pass plugins / presets, since by default it will not do anything with our code.

So, I created a .babelrc file in the project directory with the following (as in the docs)

{ "presets": ["es2015"] } 

However, this will not work. Since I use webpack and babel-loader, I came across another answer that suggested putting something like this in the webpack configuration:

 { test: /\.js$/, exclude: /node_modules/, loader: "babel", query: { presets: ["es2015"] } } 

And it works. So my question is, is this a mistake in the new Babel or is there something clearly wrong that I was missing? I used to use Babel 5 and Webpack, and I was able to specify the babel configuration in .babelrc without any problems ...

Thank you in advance

EDIT: The problem only occurs when the eslint boot loader starts before the boot loader. However, just upgraded to the latest babel-loader 6.2.0, and everything works again.

  module: { preLoaders: [ { test: /\.js$/, exclude: /node_modules/, loader: "eslint"} ], loaders: [ { test: /\.js$/, exclude: /node_modules/, loader: "babel"}, { test: /\.css$/, exclude: /node_modules/, loader: "style!css!postcss"} 
+5
source share
1 answer

There seems to be a problem with babel-loader . It should be fixed in release 6.1.0 .

You can see release / v6.1.0 :

  * release/v6.1.0: Update CHANGELOG.md and package.json Set source file name relative to options.sourceRoot Allow babelrc to be specified for cache purposes Add BABEL_ENV || NODE_ENV to default cacheIdentifier 

So it will be enough to update the babel bootloader.

+2
source

Source: https://habr.com/ru/post/1235462/


All Articles