2017-07-25 47 views
1

我只是使用react來設置webapp的環境。Babel + Webpack不會執行ES6

setInitialStates =() => { 
    this.state = {showAuthorModal: false}; 
}; 

enter image description here

注意:這是正確的語法!

發生這種情況時,我試圖運行webpack --config webpack.config.js

這是我的webpack.config.js。

const path = require('path'); 
 

 
module.exports = { 
 
    entry: { 
 
     component: [ 
 
      './public/javascripts/Rendering.jsx', 
 
      './public/javascripts/CentreQuote.jsx', 
 
      './public/javascripts/AuthorModal.jsx', 
 
      './public/javascripts/LeftNav.jsx' 
 
     ] 
 
    }, 
 
    output: { 
 
     path: path.resolve('public/javascripts'), 
 
     filename: 'index_bundle.js' 
 
    }, 
 
    module: { 
 
     loaders: [ 
 
      { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }, 
 
      { test: /\.jsx$/, loader: 'babel-loader', exclude: /node_modules/ } 
 
     ] 
 
    } 
 
}
然後,我有 .babelrc

{ 
 
    "presets":[ 
 
     "es2015", "react" 
 
    ], 
 
    "plugins": ["transform-es2015-arrow-functions"] 
 
}

我覺得我失去了鏈接babelrc到裝載機配置一些佈線工序?

回答

0

用以下內容替換 「模塊」 中的WebPack:

module: { 
    rules: [{ 
    test: /\.jsx?$/, 
    loader: "babel-loader", 
    options: { 
     cacheDirectory: true, //false for production 
     babelrc: false, 
     presets: ["es2015", "react"], 
     plugins: ["transform-es2015-arrow-functions"] 
    } 
    }] 
} 

我做了兩兩件事:

  1. 統一在一個正則表達式測試JS/JSX裝載機
  2. 使用babelrc停止能夠指定webpack內的配置。

它應該工作!試試看

與您所提供的代碼的主要問題是,你有「裝載機」,但它應該是「規則」

+1

移動通天配置成的WebPack配置不會影響任何東西,並把它們移動到一個正則表達式不能解決問題中的錯誤。 – loganfsmyth

+0

我試過你的建議,但並沒有解決問題。 –

相關問題