I am trying to build my React project for production. When I run my production command I get an error about UglifyJSPlugin saying: Unexpected token: keyword (const)
. Below I have added all my code from my package.json & webpack.config.js file. There are several questions related to this issue but none of them has worked. Any suggestions would be great.
package.json
{
...
"scripts": {
...
"prod": "NODE_ENV=production webpack -p"
},
"dependencies": {
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
...
"webpack": "^3.4.1",
"webpack-dev-server": "^2.6.1"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"uglify-js": "git://github.com/mishoo/UglifyJS2#harmony-v2.8.22",
"uglifyjs-webpack-plugin": "^0.4.6"
}
}
webpack.config.js
var path = require('path');
var webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
var debug = process.env.NODE_ENV !== 'production';
module.exports = {
context: path.join(__dirname, "src"),
devtool: debug ? "inline-sourcemap" : false,
entry: './js/client.js',
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
options: {
presets: ['stage-2', 'es2015', 'react'],
plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy']
}
},
{
test: /\.css$/,
loader: ['style-loader/url', 'file-loader']
}
]
},
output: {
path: __dirname + "/src/",
filename: 'client.min.js'
},
plugins: debug ? [] : [
new webpack.optimize.OccurrenceOrderPlugin(),
new UglifyJSPlugin({
mangle: false,
sourceMap: false
})
],
};
.babelrc
{
"presets": [
["stage-2"],
["es2015", {"modules": false}],
["react"]
]
}
UglifyJSPlugin saying that yours js files have keyword const . i think its because of output file is es6. but UglifyJSPlugin needs es5
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.