Util now, I was using Babel with the following .babelrc configuration file:
=========== Solution A ===========
{
"presets": [
"@babel/preset-env"
]
}
And, in my entrypoint app.js I directly imported:
import "core-js/stable";
import "regenerator-runtime/runtime";
=========== Solution B ===========
Recently I've read about babel-preset-env more in deep. Also based on this answer, it's more convenient to set core-js version inside .babelrc and set useBuiltIns: "usage":
{
"presets": [
["@babel/preset-env", {
"corejs": 3,
"useBuiltIns": "usage"
}]
]
}
This way, I can't get rid of the imports inside app.js because all required polyfill will be automatically included.
My question is: am I'm doing it correctly? Where to put the regenerator-runtime imports?
With the following app.js:
console.log(Array.from('foo'));
Output of npx babel src/app.js with solution A:
"use strict";
require("core-js/stable");
require("regenerator-runtime/runtime");
console.log(Array.from('foo'));
Output of npx babel src/app.js with solution B:
"use strict";
require("core-js/modules/es.array.from");
require("core-js/modules/es.string.iterator");
console.log(Array.from('foo'));