簡體   English   中英

.babelrc中指定的Babel 6預設不起作用

[英]Babel 6 presets specified in .babelrc not working

就像標題所暗示的那樣,基本上根據文檔,現在我們應該使用新的Babel 6傳遞插件/預設,因為默認情況下,它對我們的代碼不起作用。

所以我在項目目錄中使用以下命令創建了一個.babelrc文件(就像在文檔中一樣)

{
  "presets": ["es2015"]
}

但是,這不起作用。 由於我使用的是webpack和babel-loader,因此遇到了一個不同的答案,建議在Webpack配置中放入如下內容:

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

這可行。 所以我的問題是這是否是新Babel中的錯誤,還是我顯然缺少某些錯誤? 我曾經使用Babel 5和Webpack,並且能夠在.babelrc中指定babel配置沒有問題...

提前致謝

編輯:僅在運行Babel加載程序之前運行eslint加載程序時才會出現問題。 但是,只要將其更新到最新的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就足夠了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM