11const path = require ( 'path' )
2+ const resolve = require ( 'resolve' )
23const { findExisting } = require ( './util' )
34
45module . exports = function createConfigPlugin ( context , entry ) {
56 return {
67 id : '@vue/cli-service-global-config' ,
7- apply : api => {
8+ apply : ( api , options ) => {
89 api . chainWebpack ( config => {
910 // entry is *.vue file, create alias for built-in js entry
1011 if ( / \. v u e $ / . test ( entry ) ) {
@@ -19,21 +20,29 @@ module.exports = function createConfigPlugin (context, entry) {
1920 }
2021 }
2122
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
2724 const modulePath = path . resolve ( require . resolve ( 'vue' ) , '../../../' )
28-
29- config . resolve
30- . modules
31- . add ( modulePath )
32-
3325 config . resolveLoader
3426 . modules
3527 . add ( modulePath )
3628
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+
3746 // set entry
3847 config
3948 . entry ( 'app' )
0 commit comments