javascript - 为什么 Babel 导入已经支持的 polyfill?
问题描述
我正在使用rollup js
和 Babel 来转换我的 javascript,但为什么 babelpolyfill
会为“promises”添加一个?当 chrome 支持版本 33 的承诺时。我的目标是chrome version > 61
调试模式:
添加了以下内容core-js polyfill: es.promise { "chrome":"62" }
rollup.config.js
import babel from "rollup-plugin-babel";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
export default [
{
input: "src/main.js",
output: {
file: "./dist/bundle-modern.js",
format: "iife",
name: "bundle"
},
plugins: [
babel({
exclude: "node_modules/**",
presets: [
[
"@babel/preset-env",
{
targets: {
browsers: ["Chrome > 61"]
},
useBuiltIns: "usage",
corejs: 3,
debug: true
}
]
]
}),
resolve(),
commonjs()
]
}
];
main.js
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
var error = new Error(response.statusText);
error.response = response;
throw error;
}
}
function parseJSON(response) {
return response.json();
}
fetch("https://randomuser.me/api")
.then(checkStatus)
.then(parseJSON)
.then(function(data) {
console.log("request succeeded with JSON response", data.results);
})
.catch(function(error) {
console.log("request failed", error);
});
解决方案
推荐阅读
- javascript - Angular服务在构造函数中调用子方法
- r - 如何根据 R 中另一个数组的信息在数组中添加元素?
- python - Keras“准确度”指标
- java - 无法在全局配置 Mule SDK 中加载 External Lib jar
- c# - 用户在成功登录 ASP.net MVC 时未进行身份验证
- arrays - GCP Spanner 支持结构数组
- css - 使用道具值和条件检查对组件的内联样式做出反应
- android - 如何使用 Intent 获取图库图像路径
- python - 使用 DST 将本地日期时间转换为日期时间
- c++ - 如何使用来自另一个类的公共成员函数作为参数调用线程