@@ -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