fix(babel-preset-app): avoid rely on preset-env utils (#8883)

This commit is contained in:
Huáng Jùnliàng 2021-02-23 03:34:39 -05:00 committed by GitHub
parent 4a60a1934c
commit 4e3613f96f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -13,6 +13,7 @@
"@babel/compat-data": "^7.12.13",
"@babel/core": "^7.12.17",
"@babel/helper-compilation-targets": "^7.12.17",
"@babel/helper-module-imports": "^7.12.13",
"@babel/plugin-proposal-class-properties": "^7.12.13",
"@babel/plugin-proposal-decorators": "^7.12.13",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",

View File

@ -1,4 +1,18 @@
// Add polyfill imports to the first file encountered.
const { addSideEffect } = require('@babel/helper-module-imports')
const modulePathMap = {
'regenerator-runtime': 'regenerator-runtime/runtime.js'
}
function getModulePath (mod) {
return modulePathMap[mod] || 'core-js/modules/' + mod + '.js'
}
function createImport (path, mod) {
return addSideEffect(path, getModulePath(mod))
}
module.exports = ({ types }) => {
let entryFile
return {
@ -12,7 +26,6 @@ module.exports = ({ types }) => {
}
const { polyfills } = state.opts
const { createImport } = require('@babel/preset-env/lib/utils')
// Imports are injected in reverse order
polyfills.slice().reverse().forEach((p) => {