'@babel/plugin-transform-runtime' did not delete the import of 'regenerator-runtime/runtime.js' #12601
-
I looked at the demo on the documentation and tried it myself and found that the reference to the global was not deleted But the example of the document is this: "use strict";
var _regenerator = require("@babel/runtime/regenerator");
var _regenerator2 = _interopRequireDefault(_regenerator);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
var _marked = [foo].map(_regenerator2.default.mark);
function foo() {
return _regenerator2.default.wrap(
function foo$(_context) {
while (1) {
switch ((_context.prev = _context.next)) {
case 0:
case "end":
return _context.stop();
}
}
},
_marked[0],
this
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I think this is caused by a conflict with preset-env. I checked the test cases of transform-runtime and found that they are all similar to this configuration {
"plugins": ["transform-runtime", "transform-regenerator"]
} As the official documentation says, the plugin is run before preset In addition, 'transform-runtime' also has corejs conversion capabilities, and'preset-env' also has the same, I feel quite confused |
Beta Was this translation helpful? Give feedback.
-
First of all, even if there are multiple imports/requires to However, you can avoid the multiple imports by using {
"presets": [
["@babel/preset-env", {
"modules": false,
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "50",
"safari": "11.1",
"ie": "11"
}
}]
],
"plugins": [
"@babel/plugin-transform-runtime",
["@babel/plugin-proposal-decorators", { "legacy": true }],
["polyfill-corejs3", {
"method": "usage-global",
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "50",
"safari": "11.1",
"ie": "11"
}
}]
]
} Starting from Babel 7.13.0, you'll be able to avoid duplicating the {
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "50",
"safari": "11.1",
"ie": "11"
},
"presets": [
["@babel/preset-env", { "modules": false }]
],
"plugins": [
"@babel/plugin-transform-runtime",
["@babel/plugin-proposal-decorators", { "legacy": true }],
["polyfill-corejs3", { "method": "usage-global" }]
]
} EDIT: I just tested your input code with #12583, and it seems that when that PR is merged |
Beta Was this translation helpful? Give feedback.
First of all, even if there are multiple imports/requires to
regenerator
is not a problem: they all internally delegate to the same file, so it's not 7.3KB + 7.3KB + 7.2KB but just 7.3KB.However, you can avoid the multiple imports by using
babel-plugin-polyfill-corejs3
instead of theuseBuiltIns
option of@babel/preset-env
. This will be the recommended way starting from Babel 8, but you can already use it now: