Skip to content

fix: should not use absolute polyfill paths when absoluteRuntime is on #3732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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