Skip to content

Commit 9bdff3b

Browse files
authoredMar 31, 2019
fix: should not use abosulte polyfill paths when absoluteRuntime is on (#3732)
fixes #3725
1 parent b987969 commit 9bdff3b

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed
 

‎packages/@vue/babel-preset-app/__tests__/babel-preset.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,5 @@ test('disable absoluteRuntime', () => {
153153
})
154154

155155
expect(code).toMatch('import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"')
156+
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
156157
})

‎packages/@vue/babel-preset-app/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ module.exports = (context, options = {}) => {
106106
ignoreBrowserslistConfig,
107107
configPath
108108
})
109-
plugins.push([require('./polyfillsPlugin'), { polyfills, entryFiles }])
109+
plugins.push([
110+
require('./polyfillsPlugin'),
111+
{ polyfills, entryFiles, useAbsolutePath: !!absoluteRuntime }
112+
])
110113
} else {
111114
polyfills = []
112115
}

‎packages/@vue/babel-preset-app/polyfillsPlugin.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ const { addSideEffect } = require('@babel/helper-module-imports')
22

33
// slightly modifiled from @babel/preset-env/src/utils
44
// use an absolute path for core-js modules, to fix conflicts of different core-js versions
5-
function getModulePath (mod) {
6-
if (mod === 'regenerator-runtime') {
7-
return require.resolve('regenerator-runtime/runtime')
8-
}
9-
10-
return require.resolve(`core-js/modules/${mod}`)
5+
function getModulePath (mod, useAbsolutePath) {
6+
const modPath =
7+
mod === 'regenerator-runtime'
8+
? 'regenerator-runtime/runtime'
9+
: `core-js/modules/${mod}`
10+
return useAbsolutePath ? require.resolve(modPath) : modPath
1111
}
1212

13-
function createImport (path, mod) {
14-
return addSideEffect(path, getModulePath(mod))
13+
function createImport (path, mod, useAbsolutePath) {
14+
return addSideEffect(path, getModulePath(mod, useAbsolutePath))
1515
}
1616

1717
// add polyfill imports to the first file encountered.
18-
module.exports = ({ types }, { entryFiles = [] }) => {
18+
module.exports = (
19+
{ types },
20+
{ polyfills, entryFiles = [], useAbsolutePath }
21+
) => {
1922
return {
2023
name: 'vue-cli-inject-polyfills',
2124
visitor: {
@@ -24,13 +27,12 @@ module.exports = ({ types }, { entryFiles = [] }) => {
2427
return
2528
}
2629

27-
const { polyfills } = state.opts
2830
// imports are injected in reverse order
2931
polyfills
3032
.slice()
3133
.reverse()
3234
.forEach(p => {
33-
createImport(path, p)
35+
createImport(path, p, useAbsolutePath)
3436
})
3537
}
3638
}

0 commit comments

Comments
 (0)
Please sign in to comment.