I am trying to use UglifyJS to minimize/compress my bundle.js
file. When I run webpack -p
, I am getting the following:
ERROR in bundle.js from UglifyJs
Name expected [bundle.js:105519,6]
Line 105519 is as follows:
const {M, l, pattern} = __webpack_require__(862)
.
I am using React w/ ES6. Any thoughts as to what is wrong?
Every version of Webpack has a built-in version of UglifyJS (0.4.6) which doesn't support ES6. This version supports ES5 syntax only.
There are two possible solutions:
es5
Don't use the built-in version of uglifyjs-webpack-plugin
and install the latest version using npm install -D uglifyjs-webpack-plugin
. Add it to your plugins
property in your configuration:
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
plugins: [
new UglifyJSPlugin()
]
}