我正在使用rollup js
和Babel来翻译我的JavaScript,但是为什么babel为“ promises”添加polyfill
?当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);
});