Skip to content

Commit

Permalink
fix(babel-preset-app): avoid rely on preset-env utils (#8883)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored Feb 23, 2021
1 parent 4a60a19 commit 4e3613f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/babel-preset-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 14 additions & 1 deletion packages/babel-preset-app/src/polyfills-plugin.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) => {
Expand Down

0 comments on commit 4e3613f

Please sign in to comment.