babel里@babel/plugin-transform-runtime没什么效果?

给点阳光yh
  • 281

源代码:

let promise = new Promise(function (resolve,reject) {
    setTimeout(()=>{resolve()},1000)
})
Array.from(new Set([1, 2, 3, 2, 1])); 
[1, 2, NaN, 3, 4].findIndex(isNaN);  

先用下面的.babelrc

{
    "presets": [
        
        ["@babel/env",{
            "targets": {
              "chrome": "58",
              "ie": "10"
            },
            "useBuiltIns": "usage",
          }]
        
      ],
    "plugins": []
}

生成下面代码

"use strict";

require("core-js/modules/es6.array.find-index");

require("core-js/modules/web.dom.iterable");

require("core-js/modules/es6.array.iterator");

require("core-js/modules/es6.set");

require("core-js/modules/es6.string.iterator");

require("core-js/modules/es6.array.from");

require("core-js/modules/es6.promise");

require("core-js/modules/es6.object.to-string");

var promise = new Promise(function (resolve, reject) {
  setTimeout(function () {
    resolve();
  }, 1000);
});
Array.from(new Set([1, 2, 3, 2, 1]));
[1, 2, NaN, 3, 4].findIndex(isNaN);

然后我在plugins里面加了@babel/plugin-transform-runtime


{
    "presets": [
        
        ["@babel/env",{
            "targets": {
              "chrome": "58",
              "ie": "10"
            },
            "useBuiltIns": "usage",
          }]
        
      ],
    "plugins": [
         "@babel/plugin-transform-runtime"
      ]
}
但是最后生成的代码还是和之前一模一样的,这是咋回事呀
回复
阅读 2k
2 个回答
你知道吗?

宣传栏