@@ -7,7 +7,7 @@ const PluginAPI = require('./PluginAPI')
7
7
const dotenv = require ( 'dotenv' )
8
8
const dotenvExpand = require ( 'dotenv-expand' )
9
9
const defaultsDeep = require ( 'lodash.defaultsdeep' )
10
- const { chalk, warn, error, isPlugin, resolvePluginId, loadModule, resolvePkg } = require ( '@vue/cli-shared-utils' )
10
+ const { chalk, warn, error, isPlugin, resolvePluginId, loadModule, resolvePkg, resolveModule } = require ( '@vue/cli-shared-utils' )
11
11
12
12
const { defaults, validate } = require ( './options' )
13
13
const checkWebpack = require ( '@vue/cli-service/lib/util/checkWebpack' )
@@ -143,9 +143,9 @@ module.exports = class Service {
143
143
}
144
144
145
145
resolvePlugins ( inlinePlugins , useBuiltIn ) {
146
- const idToPlugin = id => ( {
146
+ const idToPlugin = ( id , absolutePath ) => ( {
147
147
id : id . replace ( / ^ .\/ / , 'built-in:' ) ,
148
- apply : require ( id )
148
+ apply : require ( absolutePath || id )
149
149
} )
150
150
151
151
let plugins
@@ -161,7 +161,7 @@ module.exports = class Service {
161
161
'./config/css' ,
162
162
'./config/prod' ,
163
163
'./config/app'
164
- ] . map ( idToPlugin )
164
+ ] . map ( ( id ) => idToPlugin ( id ) )
165
165
166
166
if ( inlinePlugins ) {
167
167
plugins = useBuiltIn !== false
@@ -176,16 +176,15 @@ module.exports = class Service {
176
176
this . pkg . optionalDependencies &&
177
177
id in this . pkg . optionalDependencies
178
178
) {
179
- let apply = ( ) => { }
180
- try {
181
- apply = require ( id )
182
- } catch ( e ) {
179
+ let apply = loadModule ( id , this . pkgContext )
180
+ if ( ! apply ) {
183
181
warn ( `Optional dependency ${ id } is not installed.` )
182
+ apply = ( ) => { }
184
183
}
185
184
186
185
return { id, apply }
187
186
} else {
188
- return idToPlugin ( id )
187
+ return idToPlugin ( id , resolveModule ( id , this . pkgContext ) )
189
188
}
190
189
} )
191
190
plugins = builtInPlugins . concat ( projectPlugins )
0 commit comments