deinhandy's avatar

LaravelMix does not uglify ES6 from node_modules

Hey Guys,

I have a default laravel mix & laravel 5.5 setup. Now, I'm trying to pull in a custom yarn package, which is written in ES6. In dev mode it works just fine. When I run in production mode, I get uglifying errors.

/js/app.js from UglifyJs
Unexpected token: punc ()) [./node_modules/my-custom-package/src/js/datepicker/datepicker.js:8,0][/js/app.js:26954,48]

The JS build in laravel mix can not handle not compiled ES6 inside of dependecies. Is there any way to make webpack work?

0 likes
1 reply
weboap's avatar

i had the same issue, ended 1-disabling the builtin uglifyJS

mix.options({
  uglify: false, 
});

then followed this post https://stackoverflow.com/questions/44287584/how-to-minify-es6-code-using-webpack

installed

"uglify-es": "^3.1.3",
"uglifyjs-webpack-plugin": "^1.0.0-beta.1",

then in webpack.mix.js

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

and added new UglifyJSPlugin() to 

mix.webpackConfig ({
                      ...
                       plugins: [
                           ...
                           new UglifyJSPlugin()
                   
                       ]
                   });

this solution have an issue of minifying the assets in prod as in dev mode. but it works.

Hope it helps.

Please or to participate in this conversation.