简体   繁体   中英

Babel 6 presets specified in .babelrc not working

as the title suggests, basically according to the docs, with the new Babel 6 we are now supposed to pass in plugins/presets since by default it would not do anything with our code.

So I created a .babelrc file in my project directory with the following (just like in the docs)

{
  "presets": ["es2015"]
}

However this would not work. Since I'm using webpack and babel-loader, I came across a different answer that suggested to put something like this in the webpack config:

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

And this works. So my question is whether this is a bug in the new Babel or there is something obviously wrong that I'm missing? I used to use Babel 5 and Webpack, and I was able to specify the babel config in .babelrc no problem...

Thanks in advance

EDIT: The problem only occurred when running the eslint loader before the babel loader. However just updated to latest babel-loader 6.2.0 and everything is working 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"}

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

You can see the release/v6.1.0 summary:

 * 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 updating babel-loader will suffice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM