@@ -2,20 +2,23 @@ const { addSideEffect } = require('@babel/helper-module-imports')
2
2
3
3
// slightly modifiled from @babel /preset-env/src/utils
4
4
// 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
11
11
}
12
12
13
- function createImport ( path , mod ) {
14
- return addSideEffect ( path , getModulePath ( mod ) )
13
+ function createImport ( path , mod , useAbsolutePath ) {
14
+ return addSideEffect ( path , getModulePath ( mod , useAbsolutePath ) )
15
15
}
16
16
17
17
// add polyfill imports to the first file encountered.
18
- module . exports = ( { types } , { entryFiles = [ ] } ) => {
18
+ module . exports = (
19
+ { types } ,
20
+ { polyfills, entryFiles = [ ] , useAbsolutePath }
21
+ ) => {
19
22
return {
20
23
name : 'vue-cli-inject-polyfills' ,
21
24
visitor : {
@@ -24,13 +27,12 @@ module.exports = ({ types }, { entryFiles = [] }) => {
24
27
return
25
28
}
26
29
27
- const { polyfills } = state . opts
28
30
// imports are injected in reverse order
29
31
polyfills
30
32
. slice ( )
31
33
. reverse ( )
32
34
. forEach ( p => {
33
- createImport ( path , p )
35
+ createImport ( path , p , useAbsolutePath )
34
36
} )
35
37
}
36
38
}
0 commit comments