-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
ES6 minify / uglify #2545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem is that UglifyJS doesn't support ES6 yet so it's not possible to avoid that transformation yet. You can follow the progress at mishoo/UglifyJS#448 . |
Even though ES6 support for UglifyJS is still under development, I would like to know how to force Webpack to use a custom version of UglifyJS, such as the Harmony branch. Is there an easy way to do this with npm? Btw, this seems to be related to #1471. |
I can see two options:
I'm not actually sure why UglifyJS plugin is at the core level as it could easily be a package of its own. Extra dependency to manage then, though. |
+1 for removing UglifyJS from the core level. |
@bebraw Or you could use |
FYI, there's a Babel specific minifier these days. See https://github.com/boopathi/babili-webpack-plugin . |
@bebraw I tried it in my project earlier, it produces unexpected results without any warnings. Same with uglifyjs2 but that happens less often than babili. Someone needs to write a bulletproof es6 minifier |
Did you see https://prosecco.surge.sh/ ? There is not much we can do about this issue in webpack itself. |
@bebraw This seems very experimental. The gitlab link returns a 404. Totally agree this isn't a webpack concern. Hence the need for removal of uglifyjs from core dependencies |
I completely agree with the first solution proposed by @bebraw. I try to help by providing detailed instructions:
to point UglifyJs2 (harmony branch) dependency to that branch.
OR,
|
@bebraw Is this still the case? Is there a way to get this for |
@mikeerickson I think the instructions above should be valid. The problem is that uglify doesn't support es6 yet and webpack bundles the plugin. So it takes quite a bit of work. |
@bebraw Which of the two items should be used
|
@mikeerickson The first sequence is all the steps (forking etc.). The second is just pointing to https://github.com/fulls1z3/webpack, but that seems to be a little out of date already. |
Ok, I will make it work. Just curious why there is no "official" version of UglifyJs which works with ES6 (harmony) within Webpack. We are well passed the ES5 days :) |
@mikeerickson I guess that's a question we have to ask from UglifyJS team. Although adding |
What if we did an experimental |
@bebraw You mean extracting lib/optimize/UglifyJsPlugin.js into separate plugin project and removing UglifyJS dependency from Webpack? Or, leaving Webpack as it is and providing users the ability to have UglifyJS plugin that instead depends on the harmony branch? |
I don't mind setting up a little stub project if you are interested. |
Hi @bebraw @mikeerickson, the fork I've been built seems a lot of of date. Now the latest version of webpack is 2.2.0, and don't worry I'll update that fork in a few days :) |
@bebraw That doesn't sound too difficult. Yea, I think I could do it. |
@fulls1z3 I don't quite understand what you are/were trying to do with that fork. There is no need to fork Webpack in order to use the harmony branch; just add |
@Kitanotori The aim of the fork is just to prevent dependency interference/mismatch (depending on the project structure, dev environment and npm). In other cases I agree with you, and voilà. |
@Kitanotori @fulls1z3 I set up a repository. There's a basic demo that works. I didn't port the tests over, though (it's a Jest based setup). |
@bebraw seems awesome! |
@Kitanotori you're right: anyway I expected the ES6-only bundle to me much smaller in size :\ |
I am using webpack 2.5.1 and "uglify-js": "git://github.com/mishoo/UglifyJS2#harmony", Now it fails with the error:
Does anyone has similar error? |
@phips28 I'm facing the exact same issue - and I have no idea what's causing it :/ |
Same here. |
UglifyJS seems to have bumped to a new major version. Try
|
@Kitanotori thx for the hint! it works |
It works until I run yarn upgrade which will overwrite it with the 2.8.23 without harmony. Anybody knows a way how to pin the transitive dependencies? |
@ksjogo That's weird. Doesn't happen for me.. Try deleting yarn.lock and node_modules and run yarn again. |
Just ran into this and while investigating discovered there is a fork of the harmony branch in NPM which seems to solve my issues ..
patched up my local uglifyjs-webpack-plugin as follows:
Ideally wouldn't be relying on a fork either, but this IMHO is better than a direct github reference.. |
https://github.com/webpack-contrib/babel-minify-webpack-plugin mentioned in the commit above from @trazyn seems like it has a lot of potential. Tried both beta uglify plugin and the babel plugin on my bundle; I was at 118kb for uglify-es, and 119kb for babel minify. |
I have the same trouble with ES6, babel-minify-webpack-plugin is work well with ES6 in my project. |
Installing const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
// ...
plugins: [
// expose and write the allowed env vars on the compiled bundle
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV)
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new UglifyJSPlugin({
uglifyOptions: {
beautify: false,
ecma: 6,
compress: true,
comments: false
}
})
] |
i used |
In my case, the problem was related to mangling. Setting |
bug
https://github.com/gildata/RAIO/issues/350 online demo
|
I'm pretty sure this is a duplicate, but I couldn't find another already open issue about it.
I'd like to not transpile my es6 code with babel to es5 before uglifying it: I'd rather use a minified es6 version of my codebase.
Is there any uglifier production-ready/webpack-ready for this?
Watching in the meantime:
https://gist.github.com/avdg/43002267f959210a69aa3ec0f21ed751
The text was updated successfully, but these errors were encountered: