-
-
Notifications
You must be signed in to change notification settings - Fork 158
'useBuiltIns' option force to import 'regenerator-runtime' #221
Comments
@revyh Hi! Thanks for your proposition. We already have related discussion in #84. The problem is that Babel runs per file. Also, instance methods such as "foobar".includes("foo") will not work since that would require modification of existing built-ins. So, for now, this idea might be implemented only for non-instance methods, for ex. promises or web.immediate. We could exclude it from |
2 things: one you would simply exclude regenerator from the env preset: https://github.com/babel/babel-preset-env#exclude the other is that you shouldn't be using both babel-polyfill (import core-js) and using transform-runtime because they both do the same thing. If you want to just use transform-runtime then don't use useBuiltIns since it's specifically for the polyfill |
@yavorsky If I understand you right, you wrote about customising 'transform-runtime' behaviour by add some normalization to // somewhere in 'normalize-options.js'
let useBuiltIns = {
polyfill: false,
regenerator: false,
};
if (typeof opts.useBuiltIns === 'boolean') {
useBuiltIns.polyfill = useBuiltIns.regenerator = opts.useBuiltIns;
} else if (opts.useBuiltIns && typeof opts.useBuiltIns === 'object') {
useBuiltIns = opts.useBuiltIns;
} and change this code to something like this useBuiltIns.regenerator &&
plugins.push([transformPolyfillRequirePlugin, { polyfills, regenerator }]); |
@revyh Got it! |
@yavorsky Thx for quick reply! if (useBuiltIns.regenerator) {
const regenerator = transformations.indexOf("transform-regenerator") >= 0;
plugins.push([transformPolyfillRequirePlugin, { polyfills, regenerator }]);
} |
@revyh If I understand correctly: useBuiltIns: {
polyfill: true,
regenerator: false
} won't pass the check and transformPolyfillRequirePlugin won't be added. |
yes |
This issue has been automatically marked as |
This issue has been moved to babel/babel#6632. |
Basicly my
.babelrc
file looks like this:And then in entry point I use
import 'core-js';
.The idea is to always import 'core-js' for polyfilling standard library and import helpers and regenerator runtime only when it's really used in code (via 'transform-runtime' plugin).
useBuiltIns
can be great improvement to this scenario that will reduce number of 'core-js' polyfills. ButuseBuiltIns
forces to import regenerator runtime if 'transform-regenerator' is included to preset. I don't want to exclude 'transform-regenerator', I want to manage regenerator runtime through 'transform-runtime'.Maybe it would be better to accept
useBuildIns
as a boolean and as an object?The text was updated successfully, but these errors were encountered: