2016-10-04 75 views
0

下面是我的WebPack配置:爲什麼我的babel poyfill不工作?

var Path = require('path'); 

module.exports = { 
    entry: { 
     create: ['babel-polyfill', Path.resolve(__dirname, "./src/create.js")], 
    }, 
    output: { 
    path: Path.resolve(__dirname, "../../public/crm/js/"), 
    filename: '[name].js' 
    }, 
    module: { 
    loaders: [ 
     { 
      test: /\.js$/, 
      exclude: /node_modules/, 
      loader: 'babel-loader?presets[]=es2015,presets[]=react' 
     } 
    ] 
} 
} 

我也NPM已經安裝這些模塊:

"babel-core": "^6.17.0", 
"babel-loader": "^6.2.5", 
"babel-polyfill": "^6.16.0", 
"babel-preset-es2015": "^6.13.2", 
"babel-preset-react": "^6.16.0" 

這裏是我的create.js文件:

import "babel-polyfill"; 
import React, { Component } from 'react'; 
import ReactDOM from 'react-dom'; 

export default class Select extends Component { 

    //some code 

    onKeyDown = (e) => { 
    const {values} = this.props 
    const idx = values.indexOf(this.state.selection) 
    if (e.keyCode === 38 && idx > 0) { /* up */ 
     this.setState({ 
     selection: values[idx - 1] 
     }) 
    } else if (e.keyCode === 40 && idx < values.length -1) { /* down */ 
     this.setState({ 
     selection: values[idx + 1] 
     }) 
    } 
    this.fireOnSelect() 
    } 

    //some code 

} 

這裏是我的來自主機的錯誤信息:

ERROR in ./src/create.js 
Module build failed: SyntaxError: Unexpected token (36:12) 

    34 | } 
    35 | 
> 36 | onKeyDown = (e) => { 
    |   ^
    37 |  const {values} = this.props 
    38 |  const idx = values.indexOf(this.state.selection) 
    39 |  if (e.keyCode === 38 && idx > 0) 

我做錯了什麼?我沒有正確設置babel polypill嗎?

+1

我不確定您的任何依賴包括該語法所需的[class properties transform](https://babeljs.io/docs/plugins/transform-class-properties/)。嘗試添加到你的依賴/巴貝爾配置 – CodingIntrigue

回答