Skip to content

Commit

Permalink
fix: should not use abosulte polyfill paths when absoluteRuntime is…
Browse files Browse the repository at this point in the history
… on (#3732)

fixes #3725
  • Loading branch information
sodatea committed Mar 31, 2019
1 parent b987969 commit 9bdff3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Expand Up @@ -153,4 +153,5 @@ test('disable absoluteRuntime', () => {
})

expect(code).toMatch('import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"')
expect(code).not.toMatch(genCoreJSImportRegExp('es6.promise'))
})
5 changes: 4 additions & 1 deletion packages/@vue/babel-preset-app/index.js
Expand Up @@ -106,7 +106,10 @@ module.exports = (context, options = {}) => {
ignoreBrowserslistConfig,
configPath
})
plugins.push([require('./polyfillsPlugin'), { polyfills, entryFiles }])
plugins.push([
require('./polyfillsPlugin'),
{ polyfills, entryFiles, useAbsolutePath: !!absoluteRuntime }
])
} else {
polyfills = []
}
Expand Down
24 changes: 13 additions & 11 deletions packages/@vue/babel-preset-app/polyfillsPlugin.js
Expand Up @@ -2,20 +2,23 @@ const { addSideEffect } = require('@babel/helper-module-imports')

// slightly modifiled from @babel/preset-env/src/utils
// use an absolute path for core-js modules, to fix conflicts of different core-js versions
function getModulePath (mod) {
if (mod === 'regenerator-runtime') {
return require.resolve('regenerator-runtime/runtime')
}

return require.resolve(`core-js/modules/${mod}`)
function getModulePath (mod, useAbsolutePath) {
const modPath =
mod === 'regenerator-runtime'
? 'regenerator-runtime/runtime'
: `core-js/modules/${mod}`
return useAbsolutePath ? require.resolve(modPath) : modPath
}

function createImport (path, mod) {
return addSideEffect(path, getModulePath(mod))
function createImport (path, mod, useAbsolutePath) {
return addSideEffect(path, getModulePath(mod, useAbsolutePath))
}

// add polyfill imports to the first file encountered.
module.exports = ({ types }, { entryFiles = [] }) => {
module.exports = (
{ types },
{ polyfills, entryFiles = [], useAbsolutePath }
) => {
return {
name: 'vue-cli-inject-polyfills',
visitor: {
Expand All @@ -24,13 +27,12 @@ module.exports = ({ types }, { entryFiles = [] }) => {
return
}

const { polyfills } = state.opts
// imports are injected in reverse order
polyfills
.slice()
.reverse()
.forEach(p => {
createImport(path, p)
createImport(path, p, useAbsolutePath)
})
}
}
Expand Down

0 comments on commit 9bdff3b

Please sign in to comment.