Build Error in Webpack UglifyJs
jianbingfang opened this issue · comments
Hi, I want use this package in browser side, but it seems have some problems with uglify plugin:
webpack -p --progress --hide-modules --env.prod
Hash: 85f427aa06d3a4f60d6e
Version: webpack 2.4.1
Time: 69750ms
Asset Size Chunks Chunk Names
index.js?7b9782135fcefaae71be 1.13 MB 1 [emitted] [big] index
d961fdfabbe512d2675de09af09f598b.svg 31 kB [emitted]
674f50d287a8c48dc19ba404d20fe713.eot 166 kB [emitted]
912ec66d7572ff821749319396470bde.svg 444 kB [emitted] [big]
b06871f281fee6b241d60582ae9369b9.ttf 166 kB [emitted]
af7ae505a9eed503f8b8e6982036873e.woff2 77.2 kB [emitted]
fee66e712a8a08eef5805a46892932ad.woff 98 kB [emitted]
vendor.js?df031a4f6465e884b124 4.39 MB 0 [emitted] [big] vendor
6f0a76321d30f3c8120915e57f7bd77e.ttf 11 kB [emitted]
manifest.js?086828a58800f469472c 1.49 kB 2 [emitted] manifest
vendor.js.map?df031a4f6465e884b124 23 MB 0 [emitted] [big] vendor
index.js.map?7b9782135fcefaae71be 1.29 MB 1 [emitted] [big] index
manifest.js.map?086828a58800f469472c 14.3 kB 2 [emitted] manifest
favicon.ico 15.4 kB [emitted]
index.html 431 bytes [emitted]
ERROR in index.js?7b9782135fcefaae71be from UglifyJs
Invalid assignment [./~/@iarna/toml/lib/format-num.js:2,0][index.js?7b9782135fcefaae71be:5150,26]
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Currently I have to disable the uglify.
Interesting! Off hand, I have no idea why that would be happening, but I'll take a look. I'm tentatively planning to update publication to use @pika/pack
, which would build a prebundled version, and maybe that will also help address (or at least ensure) that these kinds of things don't pop up unexpectedly in the future.
Ok, so a... checks watch.. year later. Uglify seems to just not support a lot of modern javascript syntax. That specific file is using an arrow function... changing it to a regular function fixes it for that file, but it fails with other files that use things like classes will also fail.
What you're going to want to do is run things through babel before uglify gets to them, so it gets the es5 it expects.