【发布时间】:2018-04-15 08:51:51
【问题描述】:
我在执行 npm run build 时不断收到此错误
真正奇怪的是,当我运行npm run watch 时,编译成功完成。
ERROR in rbz_bundle.js from UglifyJs
Unexpected token: punc (,) [xxx.js:102316,12]
这是我的 package.json 依赖项和脚本:
{
"scripts": {
"build": "webpack -p --define process.env.NODE_ENV='\"production\"' --progress --colors --config ./webpack.prod.config.js",
"watch": "webpack-dev-server -d --hot --inline --define process.env.NODE_ENV='\"development\"' --progress --colors --watch --config ./webpack.dev.config.js",
"test": "react-scripts test"
},
"dependencies": {
"axios": "^0.17.1",
"classnames": "^2.2.5",
"firebase": "^4.10.0",
"material-ui": "^1.0.0-beta.34",
"material-ui-icons": "^1.0.0-beta.17",
"npm": "^5.8.0",
"prop-types": "^15.6.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-loader": "^7.1.2",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2017": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"compression-webpack-plugin": "^1.1.7",
"css-loader": "^0.28.9",
"eslint": "^4.18.0",
"eslint-config-react-app": "^2.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.6.1",
"extract-text-webpack-plugin": "^3.0.2",
"html-replace-webpack-plugin": "^2.2.8",
"node-sass": "^4.7.2",
"react-hot-loader": "^3.1.3",
"react-scripts": "^1.1.1",
"sass-loader": "^6.0.6",
"style-loader": "^0.19.1",
"uglifyjs-webpack-plugin": "^1.2.0",
"webpack": "^3.11.0",
"webpack-dev-server": "^2.11.1",
"webpack-watch-livereload-plugin": "0.0.1",
"write-file-webpack-plugin": "^4.2.0"
}
}
由于某些未知原因,我无法修复此问题,我看到有人建议添加 "uglify-js": "git+https://github.com/mishoo/UglifyJS2.git#harmony",但它对我没有任何帮助。
----- 编辑:Webpack.prod.js ------
var webpack = require('webpack')
var path = require('path')
var extractTextPlugin = require('extract-text-webpack-plugin')
require("babel-polyfill")
module.exports = {
entry: [
'babel-polyfill', path.resolve(__dirname, 'src', 'index.js')
],
resolve: {
extensions: ['*', '.js', '.jsx']
},
output: {
path: path.resolve(__dirname, '..', 'xxx', 'static', 'js'),
publicPath: '../xxx/static/js',
filename: 'xxx.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader']
},
{
test: /\.(sass|scss)$/,
loader: extractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new extractTextPlugin({
filename: '../xxx/static/css/xxx.css',
allChunks: true
}),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
compress: {
warnings: false
}
}),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
})
]
}
【问题讨论】:
-
你能更新你的 webpack 配置吗?
-
我已经添加了 webpack 文件
-
你能分享你的 .babelrc 文件吗?