来自UglifyJs的错误意外的令牌关键字,预期的punc

时间:2018-02-17 21:13:48

标签: reactjs webpack babeljs babel

尝试在我的项目上运行npm install时出现以下错误:ERROR in bundle.js from UglifyJs Unexpected token keyword «function», expected punc «,»

我知道这是因为我正在尝试使用ES6功能,但我觉得我的设置有问题,这就是为什么它不会被Babel编译到ES5。

我已经看过关于这个问题的SO上的一些问题,并且我已经结合了一些这些答案,但没有一个解决了这个问题。

这是我的package.json

{
    "name": "my-project",
    "version": "0.0.1",
    "engines": {
        "node": "8.9.1"
    },
    "private": true,
    "scripts": {
        "dev": "webpack --progress --colors --watch",
        "postinstall": "NODE_ENV=prod webpack -p"
    },
    "dependencies": {
        "babel-core": "^6.7.4",
        "babel-loader": "^7.1.2",
        "babel-plugin-transform-react-jsx": "^6.1.18",
        "babel-preset-es2015": "^6.6.0",
        "babel-preset-react": "^6.5.0",
        "body-parser": "^1.18.2",
        "express": "^4.16.2",
        "material-ui": "^0.20.0",
        "react": "^16.2.0",
        "react-dom": "^16.2.0",
        "react-player": "^1.1.2",
        "react-render": "^1.2.1",
        "webpack": "^3.11.0",
        "yargs": "^11.0.0"
    },
    "babel": {
        "plugins": [
            "transform-react-jsx"
        ],
        "presets": [
            "es2015",
            "react"
        ]
    },
    "devDependencies": {
        "uglifyjs-webpack-plugin": "^1.2.0"
    }

}

和我的webpack.config.babel.js

var UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  context: __dirname + "/static",

  entry: {
    client: ['./App.js']
  },
  output: {
    filename: 'bundle.js',
    path: __dirname + "/static/build"
  },
  resolve: {
      extensions: ['*', '.js']
  },
  plugins: [
      new UglifyJSPlugin({
      include: /\.min\.js$/
    })
  ],
  module: {
    loaders: [
      {
        test: /(\.js$)/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
            presets: [
                'react',
                ['es2015', {'modules': false}]
            ]
        }
      }
    ]
  }
};

0 个答案:

没有答案