问题描述
现在,我一直在使用Babel和以下.babelrc
配置文件:
===========解决方案A ===========
{
"presets": [
"@babel/preset-env"
]
}
然后,在我的入口点 app.js
中,我直接导入:
import "core-js/stable";
import "regenerator-runtime/runtime";
===========解决方案B ===========
最近,我更深入地了解了babel-preset-env
。同样基于on this answer,在.babelrc
内设置core-js版本并设置useBuiltIns: "usage"
更方便:
{
"presets": [
["@babel/preset-env",{
"corejs": 3,"useBuiltIns": "usage"
}]
]
}
这样,我无法摆脱app.js
内部的导入,因为所有必需的polyfill将被自动包括在内。
我的问题是:我做对了吗?将regenerator-runtime
导入放在哪里?
使用以下app.js
:
console.log(Array.from('foo'));
使用{strong>解决方案A 的npx babel src/app.js
的输出:
"use strict";
require("core-js/stable");
require("regenerator-runtime/runtime");
console.log(Array.from('foo'));
使用{strong>解决方案B 的npx babel src/app.js
输出:
"use strict";
require("core-js/modules/es.array.from");
require("core-js/modules/es.string.iterator");
console.log(Array.from('foo'));
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)