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

Babel 6 presets specified in .babelrc not working

如标题所示,基本上根据文档,对于新的 Babel 6,我们现在应该传入 plugins/presets 因为默认情况下它不会对我们的代码执行任何操作。

所以我在我的项目目录中创建了一个 .babelrc 文件,其中包含以下内容(就像在文档中一样)

{
  "presets": ["es2015"]
}

然而这是行不通的。 因为我使用的是 webpack 和 babel-loader,所以我遇到了一个不同的答案,建议在 webpack 配置中加入这样的内容:

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

这行得通。 所以我的问题是,这是否是新 Babel 中的错误,还是我遗漏了明显的错误?我曾经使用过 Babel 5 和 Webpack,我可以在 .babelrc 中指定 babel 配置没问题...

提前致谢

编辑:问题只发生在 运行 eslint 加载器在 babel 加载器之前。然而,刚刚更新到最新的 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"}

babel-loader 似乎有问题。它应该在版本 6.1.0.

中修复

您可以看到 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

所以更新 babel-loader 就足够了。