Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

feat: update to uglify-es #55

Closed
wants to merge 9 commits into from
Closed

feat: update to uglify-es #55

wants to merge 9 commits into from

Conversation

Hartorn
Copy link
Contributor

@Hartorn Hartorn commented Jun 24, 2017

I tried this, because I wanted to be able to use webpack, with uglify es and not js.

Basically, I moved the options for Uglify into uglifyOptions key, and added an option for ES5 or ES6.

I also changed the code, to use the uglify.minify method.

Not sure if I understood something wrong, but I hope this can help.
I can correct this if needed (tested on some of my projects, and it seemed to work)

EDIT :
Here is a quick sum up of the modifications, please ask for precisions if needed.

  • Uglify now expose a single high level function minify(code, options), which go through all the steps of minification (parse, compress, mangle, output)
  • it does not throw errors anymore, so the try-catch is not needed (test if there is an error key in the return of the function)
  • it is possible to get the warnings in the result also, so it is not needed anymore to mingle with AST_NODE warn_function
  • it is possible to give a filter for comments, so we can hook on that for exporting comments
  • it is possible to give a preamble in the output, so we can use that for the banner thing (License file, comments, ...)

Basically, we do not need to use any other function than minify from uglify, it is mainly about giving proper options, handle the source maps and output.

I did not had time to update the docs, will do in the next days.

@jsf-clabot
Copy link

jsf-clabot commented Jun 24, 2017

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 5 committers have signed the CLA.

✅ bebraw
✅ d3viant0ne
✅ mkarajohn
❌ SebastianS90
❌ jumoel

@michael-ciniawsky michael-ciniawsky changed the title Allowing to use both ES5 or ES6 Uglify 3 feat: allow usage of both ES5 or ES2015 uglify versions Jun 26, 2017
@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jun 26, 2017

Fixes #32, #33

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate a bit on the removals? They are related to the breaking API changes between ugilfy-js && ugilfy-es ?

src/index.js Outdated
const RequestShortener = require("webpack/lib/RequestShortener");
const ModuleFilenameHelpers = require("webpack/lib/ModuleFilenameHelpers");
const uglify = require("uglify-js");
const uglifyEs = require("uglify-es");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better dynamically required in L24?

src/index.js Outdated

this.uglifyOptions = Object.assign({}, this.options.uglifyOptions || {}, { sourceMap: null });

this.uglify = this.options.es6 ? uglifyEs : uglifyJs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.uglify = this.options.es6 ? require('uglify-es') : require('uglify-js');

src/index.js Outdated
if(typeof options.compressor !== "undefined") options.compress = options.compressor;
this.options = options;

this.options = Object.assign({}, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.options = options || {};

There is nothing to assign here (e.g defaults)

src/index.js Outdated
const oldWarnFunction = uglify.AST_Node.warn_function;
const warnings = [];
// Copy uglify options
const uglifyOptions = Object.assign({}, this.uglifyOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const options = this.uglifyOptions || {};

src/index.js Outdated
}
}
if(minifyResult.error) {
throw minifyResult.error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.emitError(minifyResult.error)

? Not 💯 if this.emitError is Loader API only

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jun 26, 2017

Not sure about the semver tbh, guessing it would be major

@graingert
Copy link

graingert commented Jun 26, 2017

What's the point of supporting uglify-js. Doesn't uglify-es support a superset of the functionality of uglify-js?

@graingert
Copy link

No need for peerdep either, that was just a hack to support the harmony branch on github

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jun 26, 2017

What's the point of supporting uglify-js doesn't uglify-es support a superset of the functionality of uglify-js?

Yeah... good point, we need to clearify that once and for all 😛

@michael-ciniawsky
Copy link
Member

Sry it landed in master now 😅 , could you switch again and rebase against current master one more time please 😛

package.json Outdated
@@ -82,4 +81,4 @@
},
"homepage": "https://github.com/webpack-contrib/uglifyjs-webpack-plugin",
"license": "MIT"
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid text file. Files a sequence lines terminated with a newline character.

@hulkish
Copy link
Contributor

hulkish commented Jun 29, 2017

@Hartorn can you please rebase to master?

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Jun 29, 2017

yep, please rebase against current master, sry for the inconvenience again, this is definitely the next to land 💯 😛

@hulkish
Copy link
Contributor

hulkish commented Jun 29, 2017

@Hartorn Also, i noticed you removed the wrapping try/catch here: https://github.com/webpack-contrib/uglifyjs-webpack-plugin/pull/55/files#diff-1fdf421c05c1140f6d71444ea2b27638L55. Can you explain that a bit?

@Hartorn Hartorn changed the base branch from feature-defaults to master June 29, 2017 20:28
@Hartorn
Copy link
Contributor Author

Hartorn commented Jun 29, 2017

@hulkish @michael-ciniawsky done rebasing. I will have a look at the test now.

@hulkish Uglify does not throw error anymore, instead it is given in the result object.
See the few lines above https://github.com/mishoo/UglifyJS2/tree/harmony#minify-options

@michael-ciniawsky michael-ciniawsky changed the title feat: update to uglifyes feat: update to uglify-es Jun 29, 2017
@michael-ciniawsky
Copy link
Member

⚠️ The git commit author history seems to be messed up, you either need to edit the authors via git or open a fresh PR, otherwise the CLA Bot will complain and block the PR

Hartorn added 2 commits June 30, 2017 01:46
 * Putting back try-catch (wrong asset handling)
 * Adding banner for comments after being sure comments are presents
 * Correcting filter extraction
 * Correcting error handling
@hulkish
Copy link
Contributor

hulkish commented Jun 29, 2017

@Hartorn I recommend making a new pr based on master and just re apply your changes - sorry for the hassle, but I think this is your easiest route tbh.

Also, can you please make a new test for these new options that are supported in uglify-es? see https://github.com/webpack-contrib/uglifyjs-webpack-plugin/blob/master/test/all-options.test.js for an example - you could probably just copy this test and swap out the options with your options.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants