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

Revisit targeting ES6+ #2108

Closed
gaearon opened this issue May 9, 2017 · 15 comments
Closed

Revisit targeting ES6+ #2108

gaearon opened this issue May 9, 2017 · 15 comments
Milestone

Comments

@gaearon
Copy link
Contributor

gaearon commented May 9, 2017

https://www.npmjs.com/package/uglify-es is now on npm.

AFAIK both Autoprefixer and babel-preset-env support browserslist in package.json now, and uglify-es unlocks targeting ES2015 (for apps that don't care about older browsers).

We should investigate integrating those in a cohesive way.

@gaearon gaearon added this to the 0.11.0 milestone May 9, 2017
@kasperpeulen
Copy link
Contributor

I think this is an interesting strategy:
https://medium.com/dev-channel/es6-modules-in-chrome-canary-m60-ba588dfb8ab7

Basically, it recommends shipping two kind of bundles, an ES6 bundle, that will be picked by modern browsers using the type="module" attribute on the script tag, and for older browsers an ES5 bundle, with a nomodule attribute tag.

@ro-savage
Copy link
Contributor

ro-savage commented May 20, 2017

I did a test run of dropping support for IE using uglify-es and babel-preset-env with create-react-app, running a production app with bundle size of 292K.

I found it made almost no difference to file size or execution speed. (I was hoping to get file size down).

The big issue with filesize and bundle complexity is still the importing/bundling + the NPM modules being imported being pre-complied to ES5.

Still seems worth doing just didn't have nearly the improvement I was hoping for, so removed it to minimise differences with CRA.

If I get time I'll try and submit a PR for browser targeting this week. No guarantees though.

@ro-savage
Copy link
Contributor

Changes can't be made until uglifyjs-webpack-plugin is updated to UglifyJS 3.x (Tracking issue webpack-contrib/uglifyjs-webpack-plugin#32) and then webpack is updated to include the new version.

(Unless we want to do something hacky)

@transitive-bullshit
Copy link
Contributor

note that webpack-contrib/uglifyjs-webpack-plugin#32 has been resolved in beta state.

@tbillington
Copy link

@ro-savage Do you know of any efforts to distribute ES6+ builds of libraries alongside ES5 builds? I was hoping something would come along with the module syntax but haven't seen anything. As you said ES6+ builds will have negligible improvements until then.

@ro-savage
Copy link
Contributor

ro-savage commented Sep 14, 2017

As far as I am aware, there are no major libs targeting 'modern browsers'. Until IE10/11 disappear off the radar, most libs will by default support ES5.

In terms of having ES5 and ES6 builds of the same libs. Again, I haven't seen anyone really doing it but it is a decent idea. If you convince one major lib to start doing it, then stats would become available for others to know if its worth doing.

@gaearon - What about React 16 having two libs on npm. React and React-Modern that drops support for IE?

@cristiano-belloni
Copy link

That would be cool. I don't know of any major libs targeting "modern browsers", but there are some cool new libraries distributing their code in ES6 because they only target advanced browser functionality. Not being able to create a prod build with create-react-app because they're ES6 is a bit of a showstopper. Subscribing to this issue.

@wayneashleyberry
Copy link

@ro-savage I've actually run into this a few times, there are definitely packages and authors that don't bother transpiling their code any more. At the same time, authoring many packages within private organisations... not having to add pre-publish steps would be so nice.

sindresorhus/ama#446 (comment)

@cristiano-belloni
Copy link

Also here, from the ipfs guys: ipfs-inactive/js-ipfs-http-client#611 (comment)

What I would like to see is create-react-app to upgrade to the latest uglifyJS. Asking the entire world to publish ES5 code -- https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify -- specially when pretty much the only thing we do is Arrow Functions. Let me enphasize that there is an update uglifyJS that does indeed support ES6

@jozanza
Copy link

jozanza commented Nov 28, 2017

I'm 100% on the same page as that guy. The Arrow Functions thing in particular is incredibly inconvenient.

My current workaround is just patching react-scripts by injecting my own production webpack config before builds (no UglifyJSPlugin). And after build, I post-process the build js with uglify-es:

// in package.json "scripts" section
"prebuild": "cp webpack.config.prod.js node_modules/react-scripts/config",
"postbuild": "npx uglify-es build/static/js/main.*.js -c -m -o build/static/js/$(ls build/static/js | head -n 1)",

Super gross, but I'd rather do that than eject.

@wayneashleyberry
Copy link

wayneashleyberry commented Nov 28, 2017

Looks like create-react-native-app is using uglify-es by default, it'd be so nice to have parity in this project as well!

https://github.com/facebook/metro-bundler/blob/37995e2196d1de8bfc2db2442a0cdfbb8ef70999/packages/metro-bundler/src/JSTransformer/worker/minify.js#L15

@bogdansoare
Copy link
Contributor

Would love this feature. Specifically for use in monorepos with symlinks for the local packages in ES6

@gaearon
Copy link
Contributor Author

gaearon commented Jan 8, 2018

For future reference, there are three unrelated issues here:

They’re all parts of the puzzle.

@Timer
Copy link
Contributor

Timer commented Jan 10, 2018

I'll close this as too broad scope, we have a curated set of issues tracking this now.

@Timer Timer closed this as completed Jan 10, 2018
@gaearon
Copy link
Contributor Author

gaearon commented Jan 13, 2018

FYI, we're starting the work to compile deps with babel-preset-env in Create React App: #3776

Let us know if you have feedback about how this should work.

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants