Error when minifying this package with Webpack
Closed this issue · 5 comments
Checklist
- I'm using version [1.0.5]
Description
Upgrade to the recent release of breakpoints and it is causing an error when attempting to minify using webpack.
Error Output:
/js/app.js from UglifyJs
Unexpected token: name (continues) [./node_modules/breakpoints-js/dist/breakpoints.es.js:35,0][/js/app.js:51806,8]
Looking at the recent update I would probably suspect the comments in your json file to be the culprit. amazingSurge@6c89459#diff-df39304d828831c44a2b9f38cd45289c Json does not support comments and this is going to break most minify type packages. But that's only a guess.
Hi,
In this version, i expose es module by using "module" key in package.json. Will this causing the issue? Did you using rollup or babel with webpack?
And it may using uglify-es instead of uglify-js https://www.npmjs.com/package/uglify-es-webpack-plugin?
Regards,
JimbaCheng
Some discuss on module
field in package.json
file.
http://shuheikagawa.com/blog/2017/01/05/main-jsnext-main-and-module/
https://www.reddit.com/r/javascript/comments/5jwg9c/confused_about_fields_module_and_jsnextmain_in/
https://github.com/rollup/rollup/wiki/pkg.module
https://github.com/dherman/defense-of-dot-js/blob/master/proposal.md#a-future-without-vestiges
If your webpack not support es2015, (with babel or rullup), you can config your webpack, make it using main
field only.
resolve: {
mainFields: ['main'],
},
https://webpack.js.org/configuration/resolve/#resolve-mainfields
Regards,
JimbaCheng
Thanks for the help. I am using laravel mix to manage my front end dependencies and I think mix uses uglify-js internally. I will look for a way to switch to uglify-es and see if that helps.
For using laravel mix, you can see
https://github.com/JeffreyWay/laravel-mix/blob/master/docs/quick-webpack-configuration.md
Add custom field to webpack configuration,
mainFields: ['main'],
Or you can using mix.babel()
adding the mainFields to my mix config does allow the package to build and minifiy. It all appears to be working again. Thanks.
mix.webpackConfig({
resolve: {
mainFields: ['main'],
}
});