Skip to content

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

Merged
Timer merged 3 commits into
react:nextfrom
danielberndt:patch-1
Apr 2, 2018
Merged

[next] Revert to use ecma 5 in uglifyOptions#4234
Timer merged 3 commits into
react:nextfrom
danielberndt:patch-1

Conversation

@danielberndt

Copy link
Copy Markdown
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

Timer commented Mar 31, 2018

Copy link
Copy Markdown
Contributor

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

danielberndt commented Apr 1, 2018

Copy link
Copy Markdown
Contributor Author

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

Timer commented Apr 1, 2018

Copy link
Copy Markdown
Contributor

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

Timer commented Apr 1, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

Alright, done :)

@Timer

Timer commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

Perfect, thanks for this!

@Timer Timer merged commit 2824bf2 into react: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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"why"

@gaearon

gaearon commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

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

danielberndt commented Apr 2, 2018

Copy link
Copy Markdown
Contributor Author

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

gaearon commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

Thanks for explaining.

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

Timer commented Apr 2, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

@danielberndt

Copy link
Copy Markdown
Contributor Author

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

@kopax

kopax commented Apr 13, 2018

Copy link
Copy Markdown

Hi guys, could we release a fix for v2?

@mnemanja

Copy link
Copy Markdown

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

@danielberndt

Copy link
Copy Markdown
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

Timer commented May 18, 2018

Copy link
Copy Markdown
Contributor

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