CrocoDillon / universal-react-redux-boilerplate

Step by step creation of a Universal React + Redux Boilerplate
Other
176 stars 33 forks source link

npm run build fails during UglifyJs #40

Closed disbelief closed 6 years ago

disbelief commented 6 years ago

Hi there, loving the boilerplate! It's been super helpful getting a new project up and running.

I'm having some difficulty getting the project to build successfully for production. When I run npm run build everything seems to compile fine, but UglifyJs dies with this error:

ERROR in app.3f66ca6644c1feca68e3.js from UglifyJs
Invalid assignment [app.3f66ca6644c1feca68e3.js:94066,23]

Taking a look at that line position in the generated source, I see an arrow function:

const has = (arr, key) => arr.some(x => typeof x === 'string' ? x === key : x.test(key));

I have tried upgrading to the latest webpack 3.10.0, and I've been playing around with the uglifyOptions passed into the webpack.optimize.UglifyJsPlugin but so far no luck. These are my current options:

new webpack.optimize.UglifyJsPlugin({
  compressor: {
    warnings: false
  },
  uglifyOptions: {
    ecma: 8,
    ie8: false
  }
})

Any idea what I can do to fix this?

disbelief commented 6 years ago

Got it working. This is what I did:

npm i -D uglifyjs-webpack-plugin

webpack.config.js:

const ExtractTextPlugin = require('extract-text-webpack-plugin')
+
+ const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

// ...

   plugins: [
      new ExtractTextPlugin('app.[contenthash:20].css'),
      new webpack.optimize.OccurrenceOrderPlugin(),
-      new webpack.optimize.UglifyJsPlugin({
-        compressor: {
-          warnings: false
+      new UglifyJsPlugin({
+        parallel: 2,
+        uglifyOptions: {
+          ecma: 8
        }
      }),