Comments (5)
What is the reason that it recommends
"method": "usage-pure"
and not"method": "usage-global"
?
Because usage-pure
is the equivalent of what transform-runtime
does: it doesn't modify the global objects to install the shims/polyfills. usage-global
is more similar to @babel/preset-env
's useBuiltIns
option.
As a user who wants to do the following, using
"method": "usage-global"
is more correct for me, right?
- I want to transform my code to my target environment
- I want to add polyfills automatically in my code (not caring about polluting the global namespace)
- I want the babel runtime helpers to be re-used via imports (without repetition of babel helpers in each file)
Yes! I would configure Babel like this:
{
"targets": { ... }, // you can define your targets globally, so that ever plugin can use them to optimize the output
"presets": ["@babel/preset-env"], // compile JS
"plugins": [
["polyfill-corejs3", { "method": "usage-global" }], // or "polyfill-corejs2", or "polyfill-es-shims"
"@babel/transform-runtime" // to deduplicate Babel-specific helpers
]
}
from babel-polyfills.
@nicolo-ribaudo you are amazing! That is exactly the config I had started to code to use. Great to get it confirmed.
There has been a lot of confusion along the way. But I can definitely confirm that the new way you handle this with the motivations https://github.com/babel/babel-polyfills#history-and-motivation feels much more intuitive for me who has been reading up extensively on this the past weeks as a side-project.
If preset-env
could in the future only handle transforms, and have polyfills separated as explained in this repo, I do think it will make more sense for users. Removing the polyfill options from present-env
and transform-runtime
would make this easier for users to understand on how to use this. So you get a thumbs on from me on this path you have taken 👍
from babel-polyfills.
Thanks for the feedback! 😄
from babel-polyfills.
Yes! I would configure Babel like this:
{ "targets": { ... }, // you can define your targets globally, so that ever plugin can use them to optimize the output "presets": ["@babel/preset-env"], // compile JS "plugins": [ ["polyfill-corejs3", { "method": "usage-global" }], // or "polyfill-corejs2", or "polyfill-es-shims" "@babel/transform-runtime" // to deduplicate Babel-specific helpers ] }
To @nicolo-ribaudo:
Is the ordering of plugins
correct? Shouldn't we apply @babel/transform-runtime
first and then do polyfill-corejs3
? Reference to the migration guide: https://github.com/babel/babel-polyfills/blob/main/docs/migration.md#core-js3:
"plugins": [
+ "@babel/transform-runtime",
+ ["polyfill-corejs3", {
+ "method": "usage-pure"
+ }]
]
}
I'm here from discussion: babel/babel#12605 (reply in thread)
from babel-polyfills.
The plugin order does not matter in this case.
from babel-polyfills.
Related Issues (20)
- [Bug]: `babel-plugin-polyfill-corejs3` injects imports from non-existent modules in `core-js-pure` when `version` is specified HOT 2
- preset-env doesn't import "array.push" polyfill HOT 1
- [Bug]: The documentation for babel-plugin-polyfill-corejs3 seems to have an error description? HOT 1
- `usage-pure` has incorrect optimization logic HOT 4
- No matching version found for @babel/helper-define-polyfill-provider@^0.4.1 HOT 1
- Switch semver from @nicolo-ribaudo/semver-v6 to original one HOT 1
- core-js-pure/features/instance/to-array.js does not exist HOT 1
- Excluding `es.json.stringify` does not work
- Please release HOT 1
- dom-exception polyfill import fails HOT 7
- no matcing version HOT 1
- Sorting `core-js` modules in the order from `core-js-compat`
- Why createMetaResolver ignores object for instance polyfills HOT 1
- Does babel-polyfills have any strategy to prevent creating cycles?
- Does babel-polyfills have any strategy to deal with repeated injection of different version of core-js library?
- Does the option `helpers: true` from `@babel/plugin-transform-runtime` do the same as `babel-plugin-polyfill-regenerator`? HOT 1
- Error: Can't resolve '@babel/runtime-corejs3/helpers/asyncToGenerator' HOT 1
- useBuiltIns: 'usage' will only transpile but not polyfill my nuxt v2 app
- When I use polyfill-es-shims plugin on my code it tries to import nodeJS `util.inspect` which requires rollup-plugin-polyfill-node... HOT 3
- helper-define-polyfill-provider: Cannot read properties of undefined (reading 'includes') HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-polyfills.