简体   繁体   English

.babelrc中指定的Babel 6预设不起作用

[英]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. 就像标题所暗示的那样,基本上根据文档,现在我们应该使用新的Babel 6传递插件/预设,因为默认情况下,它对我们的代码不起作用。

So I created a .babelrc file in my project directory with the following (just like in the docs) 所以我在项目目录中使用以下命令创建了一个.babelrc文件(就像在文档中一样)

{
  "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: 由于我使用的是webpack和babel-loader,因此遇到了一个不同的答案,建议在Webpack配置中放入如下内容:

{
     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? 所以我的问题是这是否是新Babel中的错误,还是我显然缺少某些错误? I used to use Babel 5 and Webpack, and I was able to specify the babel config in .babelrc no problem... 我曾经使用Babel 5和Webpack,并且能够在.babelrc中指定babel配置没有问题...

Thanks in advance 提前致谢

EDIT: The problem only occurred when running the eslint loader before the babel loader. 编辑:仅在运行Babel加载程序之前运行eslint加载程序时才会出现问题。 However just updated to latest babel-loader 6.2.0 and everything is working again. 但是,只要将其更新到最新的babel-loader 6.2.0,一切都会恢复正常。

    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 . babel-loader似乎有问题。 It should be fixed in release 6.1.0 . 它应该在版本6.1.0中修复。

You can see the release/v6.1.0 summary: 您可以看到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 updating babel-loader will suffice. 因此,更新babel-loader就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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