1
1
const path = require ( 'path' )
2
+ const resolve = require ( 'resolve' )
2
3
const { findExisting } = require ( './util' )
3
4
4
5
module . exports = function createConfigPlugin ( context , entry ) {
5
6
return {
6
7
id : '@vue/cli-service-global-config' ,
7
- apply : api => {
8
+ apply : ( api , options ) => {
8
9
api . chainWebpack ( config => {
9
10
// entry is *.vue file, create alias for built-in js entry
10
11
if ( / \. v u e $ / . test ( entry ) ) {
@@ -19,21 +20,29 @@ module.exports = function createConfigPlugin (context, entry) {
19
20
}
20
21
}
21
22
22
- // include resolve for deps of this module.
23
- // when installed globally, the location may vary depending on
24
- // package managers their folder structures for global install.
25
- // so we first resolve the location of vue and then trace to the
26
- // install location.
23
+ // ensure loaders can be resolved properly
27
24
const modulePath = path . resolve ( require . resolve ( 'vue' ) , '../../../' )
28
-
29
- config . resolve
30
- . modules
31
- . add ( modulePath )
32
-
33
25
config . resolveLoader
34
26
. modules
35
27
. add ( modulePath )
36
28
29
+ // add resolve alias for vue and vue-hot-reload-api
30
+ // but prioritize versions installed locally.
31
+ try {
32
+ resolve . sync ( 'vue' , { basedir : context } )
33
+ } catch ( e ) {
34
+ const vuePath = path . dirname ( require . resolve ( 'vue' ) )
35
+ config . resolve . alias
36
+ . set ( 'vue$' , `${ vuePath } /${ options . compiler ? `vue.esm.js` : `vue.runtime.esm.js` } ` )
37
+ }
38
+
39
+ try {
40
+ resolve . sync ( 'vue-hot-reload-api' , { basedir : context } )
41
+ } catch ( e ) {
42
+ config . resolve . alias
43
+ . set ( 'vue-hot-reload-api' , require . resolve ( 'vue-hot-reload-api' ) )
44
+ }
45
+
37
46
// set entry
38
47
config
39
48
. entry ( 'app' )
0 commit comments