-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Compile dependencies with babel-preset-env #3776
Conversation
node: 'current', | ||
}, | ||
// Do not transform modules to CJS | ||
modules: false, |
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.
Maybe we should?
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.
Since Node hasn't decided how to handle ESM I don't think we should support it
At least it passes the CI, not bad |
|
I think we can live with these numbers given how much demand there is for this feature. |
It would be nice to see if updating webpack to latest 3.x (or 4.x prereleases) could offset some of the hit. |
We could use webpack's new |
Sticking
|
😭 🎉 |
@ljharb sometimes its not an external package that is using > es5, its your own packages in an monorepo while you working on a new feature back and forth between ui-component-lib and main webapp |
@alzalabany sure, but that's a special case, and deserves an explicit opt in - that's not a safe default nor a reasonable thing to expect as a common case. |
…grade Babel setup and enable tr More context in: facebook/create-react-app#3776 BREAKING CHANGE: Now we compile third-party JavaScript code with Babel. fix #217
…grade Babel setup and enable transpilation of third-party code More context in: facebook/create-react-app#3776 BREAKING CHANGE: Now we compile third-party JavaScript code with Babel. fix #217
@ljharb how long should 3rd party libraries support ES5? IMHO this question does not have a decent answer since it depends on the actual devs using the libraries and what they support...
Compiled ES5 has a quantitative disadvantage: it is larger (and slower) than ES6+. Support for ES6+ just requires time to come, but if every library author compiles to ES5 it'll take really long time to fix in the npm community and we don't want another callbacks vs promises issue. I think it's better to support Javascript, and that libraries should do so, instead of trying to force the whole ecosystem to be locked into a single version. |
@franciscop much much longer than you can drop it in your app, and yes, effectively forever (es4 never existed). Also, compiled es5 isn’t necessarily slower - browsers optimize old patterns, not new patterns, because more people use them. Publishing a dep that’s not compiled down is what’s forcing the ecosystem to a specific level of javascript, because it means people can’t safely use your code when they want to support older engines. Either way, this isn’t something we should be debating in this thread; feel free to find me on irc. |
…grade Babel setup and enable transpilation of third-party code More context in: facebook/create-react-app#3776 BREAKING CHANGE: Now we compile third-party JavaScript code with Babel. fix #217
Having the ability to opt-in with a list of packages that need to be transpiled would actually help both arguments. You won't have to eject to transpile node_modules but aren't unnecessarily transpiling packages. My project has a ton of dependencies but only transpiling 3 packages. We had to fork the repo so we could get this behavior in our monorepo. However on the opposite side I wouldn't want to transpile everything. 🤔 |
That's tangential, so feel free to file a new issue. This behavior shipped in 2.0. |
See [Enable babel-preset-env for node_modules that target newer Node versions](facebook/create-react-app#1125) See [Create React App 2.0: "You can now use packages written for latest Node versions without breaking the build"](https://reactjs.org/blog/2018/10/01/create-react-app-v2.html) See ["If you have to exclude node_modules/, how do you get babel to polyfill/transform code in 3rd party code?"](webpack/webpack#6544 (comment)) See [Compile dependencies with babel-preset-env](facebook/create-react-app#3776)
See [Enable babel-preset-env for node_modules that target newer Node versions](facebook/create-react-app#1125) See [Create React App 2.0: "You can now use packages written for latest Node versions without breaking the build"](https://reactjs.org/blog/2018/10/01/create-react-app-v2.html) See ["If you have to exclude node_modules/, how do you get babel to polyfill/transform code in 3rd party code?"](webpack/webpack#6544 (comment)) See [Compile dependencies with babel-preset-env](facebook/create-react-app#3776)
See [Enable babel-preset-env for node_modules that target newer Node versions](facebook/create-react-app#1125) See [Create React App 2.0: "You can now use packages written for latest Node versions without breaking the build"](https://reactjs.org/blog/2018/10/01/create-react-app-v2.html) See ["If you have to exclude node_modules/, how do you get babel to polyfill/transform code in 3rd party code?"](webpack/webpack#6544 (comment)) See [Compile dependencies with babel-preset-env](facebook/create-react-app#3776)
When I search on google I end up here, but all that's here is a link to release notes and the blog post, neither of which mentions this presumably huge important feature. I'll just add what I know: as far as I can tell, create-react-app@2 just does this, no additional configuration is required. It uses a slightly more conservative config, transpiling only core es features (those which preset-env supports by default). |
Proof of concept for #1125.
This currently runs all
node_modules
throughbabel-preset-env
.(Which was unsafe in Babel 6, but should—maybe—be safe in Babel 7.)
I don't know the impact on the build time. It'll definitely make the cold start slower but hopefully repeated builds will be okay. We need some measurements with larger projects here: https://mobile.twitter.com/dan_abramov/status/952248179478745089.
I intentionally only did this for webpack. I don’t think we need to do this for tests because you control the Node version on which you run the tests, unlike the user’s browser. And it’s never required to compile because we intentionally don’t allow any custom transforms (like JSX). Only “real” JS gets compiled.
TODO:
engines
field that implies we don't need compilation).babelrc
in packages gets ignored