-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add ES6 Support #71
Add ES6 Support #71
Conversation
I think we shouldn't use terser to completely replace uglify-js. I have noticed the different behaviors when I bring up test for the plugin. |
Example? Does the behavior break browser compatibility (i.e. IE)? |
This is the result of uglify; Line 35 in 6b39c7f
And this is the result of terser: Line 64 in 6b39c7f
// UglifyJS
var x={baz_:0,foo_:1,calc:function(){return this.foo_+this.baz_},bar_:2,baz_:3};console.log(x.calc());
// Terser
var x={baz_:(0,3),foo_:1,calc:function(){return this.foo_+this.baz_},bar_:2};console.log(x.calc()); Although it is pretty much equivalent, but it still raises a question if terser would have any other different behaviors. |
It looks like Terser compresses better, which is expected since it's more advanced than UglifyJS, so they would produce different output as a result. I suggest to drop uglify in the next major (i.e. when dropping Node 8). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc
test/index.js
Outdated
|
||
const result = uglifyFilter.apply(ctx, [code, { path: 'source/test.js' }]); | ||
|
||
result.should.eql('var x={baz_:0,foo_:1,calc:function(){return this.foo_+this.baz_},bar_:2,baz_:3};console.log(x.calc());'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when hardcoding the result, it could break in newer version of uglify/terser (just like hexojs/hexo#3829). I think comparing String.length
should suffice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I just use:
const uglify = require('uglify-js');
// Just as an example. The usage of UglifyJS & Terser shouldn't be uglify(code).
uglifyFilter.apply(ctx, [code, { path: 'source/test.js' }]).should.eql(uglify(code));
Then the unit-test will become useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I mean is result.length.should.below(code.length)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even uglifyFilter.apply(ctx, [code, { path: 'source/test.js' }]).should.eql(uglify(code));
is useful
For example, try parsing config.uglify.priority
without delete jsOptions.priority
, the unit test would fail. In this case, the unit test correctly identify that the plugin wouldn't work if delete jsOptions.priority
is missing.
Another example is parsing the options
uglifyFilter.apply(ctx, [code, { path: 'source/test.js' }]).should.eql(uglify(code, options));
in this case, the unit test can check whether the plugin parse custom options correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I mean is
result.length.should.below(code.length)
.
That sounds as a good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, try parsing
config.uglify.priority
withoutdelete jsOptions.priority
, the unit test would fail. In this case, the unit test correctly identify that the plugin wouldn't work ifdelete jsOptions.priority
is missing.
If something like delete jsOptions.priority
is missing, current unit test will not passed as well because when no valid configuration is passed to UglifyJS / Terser will resulted in undefined
.
Except for the documentation and unit test, I already tested locally, WFM. |
README.md
Outdated
- **exclude**: Exclude files. Use [glob expressions](https://github.com/micromatch/micromatch#extended-globbing) for path matching. | ||
- **es6**: Enable es6 compression. Default is `false` | ||
- When enabled, hexo-uglify will use [terser](https://github.com/terser/terser) as compressor, otherwise [uglifyjs](https://github.com/mishoo/UglifyJS2) will be used. | ||
- The API & minify options of terser is fully compatible with uglifyjs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not fully compatible, e.g. Terser has Safari compatibility mode.
Close #70.
Another filter register is added in order to avoid require minifier every time the filter is executed, which might have less impact on performance.