mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-13 19:01:25 -06:00
@@ -3,6 +3,7 @@ const debug = require('debug')
|
||||
const GeneratorAPI = require('./GeneratorAPI')
|
||||
const sortObject = require('./util/sortObject')
|
||||
const writeFileTree = require('./util/writeFileTree')
|
||||
const inferRootOptions = require('./util/inferRootOptions')
|
||||
const normalizeFilePaths = require('./util/normalizeFilePaths')
|
||||
const injectImportsAndOptions = require('./util/injectImportsAndOptions')
|
||||
const { toShortPluginId, matchesPluginId } = require('@vue/cli-shared-utils')
|
||||
@@ -86,10 +87,12 @@ module.exports = class Generator {
|
||||
this.exitLogs = []
|
||||
|
||||
const cliService = plugins.find(p => p.id === '@vue/cli-service')
|
||||
const rootOptions = cliService && cliService.options
|
||||
const rootOptions = cliService
|
||||
? cliService.options
|
||||
: inferRootOptions(pkg)
|
||||
// apply generators from plugins
|
||||
plugins.forEach(({ id, apply, options }) => {
|
||||
const api = new GeneratorAPI(id, this, options, rootOptions || {})
|
||||
const api = new GeneratorAPI(id, this, options, rootOptions)
|
||||
apply(api, options, rootOptions)
|
||||
})
|
||||
}
|
||||
|
||||
31
packages/@vue/cli/lib/util/inferRootOptions.js
Normal file
31
packages/@vue/cli/lib/util/inferRootOptions.js
Normal file
@@ -0,0 +1,31 @@
|
||||
// Infer rootOptions for individual generators being invoked
|
||||
// in an existing project.
|
||||
|
||||
module.exports = function inferRootOptions (pkg) {
|
||||
const rootOptions = {}
|
||||
const deps = Object.assign({}, pkg.dependencies, pkg.devDependencies)
|
||||
|
||||
// projectName
|
||||
rootOptions.projectName = pkg.name
|
||||
|
||||
// router
|
||||
if ('vue-router' in deps) {
|
||||
rootOptions.router = true
|
||||
}
|
||||
|
||||
// vuex
|
||||
if ('vuex' in deps) {
|
||||
rootOptions.vuex = true
|
||||
}
|
||||
|
||||
// cssPreprocessors
|
||||
if ('sass-loader' in deps) {
|
||||
rootOptions.cssPreprocessor = 'sass'
|
||||
} else if ('less-loader' in deps) {
|
||||
rootOptions.cssPreprocessor = 'less'
|
||||
} else if ('stylus-loader' in deps) {
|
||||
rootOptions.cssPreprocessor = 'stylus'
|
||||
}
|
||||
|
||||
return rootOptions
|
||||
}
|
||||
Reference in New Issue
Block a user