2017-07-25 54 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

我试过你的建议,但并没有解决问题。 –

相关问题