Skip to content
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

Change to uglify es & output uglify errors #157

Merged
merged 15 commits into from
Dec 11, 2017
Merged

Change to uglify es & output uglify errors #157

merged 15 commits into from
Dec 11, 2017

Conversation

DeMoorJasper
Copy link
Member

@DeMoorJasper DeMoorJasper commented Dec 9, 2017

If uglify encountered errors it didn't get thrown, due to a change in uglify v3.X.
I'm aware the current uglify bug people reported in #8 is due to this bug: lightscript/babel-to-estree#1
EDIT: This will now also fix #8 due to no longer using estree [FIXED]

I think parcel should be using Uglify ES to support more modern babel configs & js versions to prevent future issues

Performance tests (Based on running the tests 3 times and taking the avg - On Macbook Pro dual core mid-2014)

UglifyJS UglifyES UglifyES without estree (ES6+ compatible)
JavaScript 226ms 263ms 252ms
TypeScript 100ms 126ms 133ms

Related to
closes #145 closes #124 closes #15 closes #8

@100terres
Copy link

We should also update the documentation here: https://github.com/parcel-bundler/website/blob/3c54bf479e2b1d244b30d35b15b4bab2e18d7106/src/docs/production.md

Change uglify-js to uglify-es with this link: https://github.com/mishoo/UglifyJS2/tree/harmony

const {toEstree} = require('babel-to-estree');
const types = require('babel-types');
const walk = require('babylon-walk');

module.exports = async function(asset) {
await asset.parseIfNeeded();

// Convert to UglifyJS AST
// Convert to UglifyES AST
var ast = AST_Node.from_mozilla_ast(toEstree(asset.ast, asset.contents));
Copy link

@kzc kzc Dec 9, 2017

Choose a reason for hiding this comment

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

This won't work for ES6+ code.

You either have to use the built-in uglify-es parser instead of ESTree or add ES6+ ESTree support to uglify-es.

It's an known issue that only ES5 ESTree constructs are currently converted by uglify-es: mishoo/UglifyJS#968

Copy link
Member Author

@DeMoorJasper DeMoorJasper Dec 9, 2017

Choose a reason for hiding this comment

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

Ow damn, thanks for the heads up, i'll read through that issue for sure

@@ -5,7 +5,7 @@ const walk = require('babylon-walk');
module.exports = async function(asset) {
await asset.parseIfNeeded();

// Convert to UglifyES AST
// Minify with UglifyES
Copy link

Choose a reason for hiding this comment

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

Suggest to change to "Minify with uglify-es" to match the npm package name. The term "UglifyES" is not used by its maintainers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do, tnx for the suggestion 💯

Copy link

Choose a reason for hiding this comment

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

...or better yet - drop the comment altogether.

@kzc
Copy link

kzc commented Dec 9, 2017

I'm not surprised that the timings are not impacted very much for ES6. Converting an AST is an expensive operation.

Regarding the timings for Typescript - is it faster now because an AST no longer has to be generated?

@DeMoorJasper
Copy link
Member Author

DeMoorJasper commented Dec 9, 2017

I have no clue why Typescript became so fast. It normally goes through the babel parser as well (generating the AST).
EDIT: I re-ran the Typescript tests on all branches and updated the results.
The TS example used in the tests is smaller than the JS one normally so that explains compared to JS though.

@kzc
Copy link

kzc commented Dec 9, 2017

With this PR is the babel AST still needed?

let res = babel.transformFromAst(asset.ast, asset.contents, config);
asset.ast = res.ast;
asset.isAstDirty = true;

@DeMoorJasper
Copy link
Member Author

I'm pretty sure it is, it's being used in different places

@kzc
Copy link

kzc commented Dec 10, 2017

I'm kind of puzzled by 9d59def. babel-generator and uglify-es are like oil and water unless you add ES6+ ESTree support to uglify-es. Is this for non-JS assets?

@DeMoorJasper
Copy link
Member Author

I just copied that piece of code from JSAsset.generate() to uglify, so that it would only generate code from the AST @kzc
I'm still trying to figure out all ways to improve upon this though

@kzc
Copy link

kzc commented Dec 10, 2017

Okay, I see. Uglify is only fed ES source code, not ESTree.

// Log all warnings
if (result.warnings) {
result.warnings.forEach(warning => {
// TODO: warn this using the logger
Copy link
Member Author

Choose a reason for hiding this comment

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

Would probably be better to use the logger to send warnings to the console, not really sure how to address the logger from here though

Copy link
Member

Choose a reason for hiding this comment

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

hmm yeah, the logger isn't really accessible from here, it lives only in the main process right now, not workers.

// Convert AST into JS
let code = asset.isAstDirty
? generate(asset.ast).code
: asset.outputCode || asset.contents;
Copy link
Member

Choose a reason for hiding this comment

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

maybe just call asset.generate().js here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I extracted this bit from generate because i saw TODO: Source maps and thought this would affect performance in the future. I'll change it back to asset.generate though :)

// Log all warnings
if (result.warnings) {
result.warnings.forEach(warning => {
// TODO: warn this using the logger
Copy link
Member

Choose a reason for hiding this comment

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

hmm yeah, the logger isn't really accessible from here, it lives only in the main process right now, not workers.

@devongovett devongovett merged commit 70663cc into parcel-bundler:master Dec 11, 2017
@DeMoorJasper DeMoorJasper deleted the feature/uglify-es-support branch December 11, 2017 13:32
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* uglify-es

* fix error handling

* dump estree, enables ES6+ support

* fix comment

* change comment to match npm package name

* remove useless comment

* remove unused imports, change asset.generate to babel generate

* improve minify options

* fix comment

* remove unused import

* pivot back to asset.generate().js
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* uglify-es

* fix error handling

* dump estree, enables ES6+ support

* fix comment

* change comment to match npm package name

* remove useless comment

* remove unused imports, change asset.generate to babel generate

* improve minify options

* fix comment

* remove unused import

* pivot back to asset.generate().js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants