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

[next] Revert to use ecma 5 in uglifyOptions #4234

Merged
merged 3 commits into from
Apr 2, 2018

Conversation

danielberndt
Copy link
Contributor

Building my app using the [next] version of react-scripts lead to issues when trying to open the minified results on IE11.

It's a combination of using the commonmark.js library and using the {ecma: 8} in the uglifyOptions. That led to unicode characters in the output that can't be parsed by IE11. Also the Google crawler bot is yelling Unexpected token ILLEGAL at the resulting code.

Look here for another discussion about the same issue: rails/webpacker#1235

@Timer
Copy link
Contributor

Timer commented Mar 31, 2018

This will impact parsing of newer browser syntax, no? I believe #4221 is related.

There is probably an uglify option we can shut off to disable this behavior -- I'd rather do that instead.

@Timer Timer added this to the 2.0.0 milestone Mar 31, 2018
@danielberndt
Copy link
Contributor Author

danielberndt commented Apr 1, 2018

Ah, yes, a closer look into the docs reveals that you can place the ecma option for each of parse, compress, and output. So I believe what we want is something like

{
  parse: {ecma: 8,...},
  compress: {ecma: 5,...},
  output: {ecma: 5,...},
}

which are the default values already. So I think the simplest thing is to not have any explicit ecma setting on our end.

The defaults are already what we want
@Timer
Copy link
Contributor

Timer commented Apr 1, 2018

Output is not necessarily going to be ecma: 5 though -- it's whatever browser you target.

Can you provide a sample output of something using newer features against this setting? e.g. 5 ** Math.PI.

@Timer
Copy link
Contributor

Timer commented Apr 1, 2018

Oh, I just toyed with this and it appears ecma: 5 still outputs ES5+ syntax (weird).

Let's be explicit and do to prevent any upstream changes by accident:

{
  parse: {ecma: 8,...},
  compress: {ecma: 5,...},
  output: {ecma: 5,...},
}

And add an explanation for why the values are as such (and a link to this issue preceding it all).

@danielberndt
Copy link
Contributor Author

Alright, done :)

@Timer
Copy link
Contributor

Timer commented Apr 2, 2018

Perfect, thanks for this!

@Timer Timer merged commit 2824bf2 into facebook:next Apr 2, 2018
parse: {
// we want uglify-js to parse ecma 8 code. However we want it to output
// ecma 5 compliant code, to avoid issues with older browsers, this is
// whey we put `ecma: 5` to the compress and output section
Copy link
Contributor

Choose a reason for hiding this comment

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

"why"

@gaearon
Copy link
Contributor

gaearon commented Apr 2, 2018

I'm a bit confused. Didn't we want to let people ship uncompiled code in production too if they don't care about older browsers per their browserlist?

@danielberndt
Copy link
Contributor Author

danielberndt commented Apr 2, 2018

uglify-es is currently not configured to consider the browserlist settings.
The previous settings lead to code that couldn't be parsed on old browsers, no matter what you put in your browserlist.

Also: this setting won't transpile your code down to es5, it will just avoid minification steps that only work for es6+.

For example: an ecma setting of 5 will not convert ES6+ code to ES5.
https://www.npmjs.com/package/uglify-es

@gaearon
Copy link
Contributor

gaearon commented Apr 2, 2018

Thanks for explaining.

@danielberndt danielberndt deleted the patch-1 branch April 2, 2018 17:57
@Timer
Copy link
Contributor

Timer commented Apr 2, 2018

Yeah, it's a little counter-intuitive -- setting output: 5 still outputs ES6+ code/syntax -- this really confused me at first (it only disables es6+ optimizations).
I figure this is the best solution until uglify respects browserslist.

@danielberndt did you want to send a follow up to tweak the docs / fix that "why"?

Also, how about we open an issue with uglify about supporting browserslist?

@danielberndt
Copy link
Contributor Author

Sure, will put a short version of my explanation as a code comment :)

@danielberndt
Copy link
Contributor Author

Ah now I see! The "why" was referring to a typo, and not a question 😅

@kopax
Copy link

kopax commented Apr 13, 2018

Hi guys, could we release a fix for v2?

@mnemanja
Copy link

I'd appreciate this as well. When can it be expected?

@danielberndt
Copy link
Contributor Author

It's already released :)

you can check it here: https://unpkg.com/react-scripts@2.0.0-next.66cc7a90/config/webpack.config.prod.js

@Timer
Copy link
Contributor

Timer commented May 18, 2018

Be sure you always install react-scripts@next --exact; never trust upgrade on a caret range.

zmitry pushed a commit to zmitry/create-react-app that referenced this pull request Sep 30, 2018
* Revert to use ecma 5 in uglifyOptions

* remove explicit ecma version from uglifyOptions settings

The defaults are already what we want

* be explicit of where we use ecma: 8 and ecma: 5
@lock lock bot locked and limited conversation to collaborators Jan 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants