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

deprecates babel/polyfill in favor of core-js@3 #2031

Merged
merged 1 commit into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/es6.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ Following ES6/7 features are supported out of the box:
* Dynamic import() - useful for route level code-splitting
* Class Fields and Static Properties.

We have also included [babel polyfill](https://babeljs.io/docs/usage/polyfill/)
that includes a custom regenerator runtime and core-js.
We have also included [core-js](https://github.com/zloirock/core-js) to polyfill features in the
older browsers.

Don't forget to import `@babel/polyfill` in your main entry point like so:
Don't forget to add these lines into your main entry point:

```js
import "@babel/polyfill"
import "core-js/stable";
import "regenerator-runtime/runtime";
```


Expand Down
4 changes: 3 additions & 1 deletion lib/install/config/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function(api) {
{
forceAllTransforms: true,
useBuiltIns: 'entry',
Copy link
Contributor

Choose a reason for hiding this comment

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

@gauravtiwari do you think usage should be the new default? From here:

Until Babel 7.3, useBuiltIns: usage was unstable and not fully reliable: many polyfills were not included, and many others were added without their required dependencies. In Babel 7.4, I tried to make it understand every possible usage pattern.

it does look like it's stable now. If I understand it correctly, using usage won't require additional import. When I use:

import "core-js";

in my entry point, I get the following message:

When setting `useBuiltIns: 'usage'`, polyfills are automatically imported when needed.
Please remove the direct import of `core-js` or use `useBuiltIns: 'entry'` instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would question that. useBuiltIns: 'usage' is not assuming anything about user's code, just expect to change import core-js to required imports based on supported env, so you need to opt-in in into it by adding that import into one of your packs.
If we switch that to usage, it stops being opt-in and starts automatically adding imports to the code. And from my experience, it still has some edge-cases (because core-js detects relevant import by statically analyzing, so it could not predict what you could have in a runtime), so that creates cases when you still need to add some polyfills by hand.

To summarize: I think useBuiltIns: 'usage' is a safer choice, in general, that is very easy to change if you know what you're doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense 👍

corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@somebody32 This suggests that @babel/plugin-transform-runtime (line 56) can specify to use corejs: 3 as dependency. Were you able to make that work? I'm still seeing errors like these when I make that change:

Screen Shot 2019-04-18 at 11 11 44 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great point, looks like I need to extend that too (was not using it in our project, that is why didn't spot the problem): https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md#babelruntime

tldr: try to add @babel/runtime-corejs3 package

Expand All @@ -56,7 +57,8 @@ module.exports = function(api) {
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true
regenerator: true,
corejs: 3
}
],
[
Expand Down
1 change: 1 addition & 0 deletions lib/install/examples/react/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function(api) {
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
Expand Down
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
"yarn": ">=1.0.0"
},
"dependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
"@babel/core": "^7.4.0",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-destructuring": "^7.3.2",
"@babel/plugin-transform-regenerator": "^7.3.4",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.4",
"@babel/runtime": "^7.3.4",
"@babel/plugin-transform-destructuring": "^7.4.0",
"@babel/plugin-transform-regenerator": "^7.4.0",
"@babel/plugin-transform-runtime": "^7.4.0",
"@babel/preset-env": "^7.4.0",
"@babel/runtime": "^7.4.0",
"@babel/runtime-corejs3": "^7.4.3",
"babel-loader": "^8.0.5",
"babel-plugin-dynamic-import-node": "^2.2.0",
"babel-plugin-macros": "^2.5.0",
"case-sensitive-paths-webpack-plugin": "^2.2.0",
"compression-webpack-plugin": "^2.0.0",
"core-js": "^3.0.0",
"css-loader": "^2.1.1",
"file-loader": "^3.0.1",
"flatted": "^2.0.0",
Expand All @@ -42,6 +43,7 @@
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.6.0",
"postcss-safe-parser": "^4.0.1",
"regenerator-runtime": "^0.13.2",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.2.3",
Expand Down
2 changes: 1 addition & 1 deletion package/rules/node_modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { nodeEnv } = require('../env')
module.exports = {
test: /\.(js|mjs)$/,
include: /node_modules/,
exclude: /@babel(?:\/|\\{1,2})runtime/,
exclude: /@babel(?:\/|\\{1,2})runtime|core-js/,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

running babel on core-js is causing issues

use: [
{
loader: 'babel-loader',
Expand Down
Loading