Skip to content

Commit a4df112

Browse files
author
test
committed
feat(cli): add ability to add vuex and vue-router internal plugins (vuejs#1202)
1 parent a6e47ce commit a4df112

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/@vue/cli/lib/add.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,30 @@ const { resolveModule } = require('./util/module')
66
const {
77
log,
88
error,
9+
warn,
910
hasYarn,
1011
stopSpinner,
1112
resolvePluginId
1213
} = require('@vue/cli-shared-utils')
1314

15+
// vuex and vue-router are internally added via cli-service so they need to be handled differently
16+
const internalPluginRE = /^(vuex|router)$/
17+
1418
async function add (pluginName, options = {}, context = process.cwd()) {
15-
const packageName = resolvePluginId(pluginName)
19+
let packageName
20+
const internalPlugin = internalPluginRE.test(pluginName)
21+
if (internalPlugin) {
22+
packageName = pluginName.replace(/router/, 'vue-router')
23+
} else {
24+
packageName = resolvePluginId(pluginName)
25+
}
1626

1727
log()
1828
log(`📦 Installing ${chalk.cyan(packageName)}...`)
1929
log()
2030

2131
const packageManager = loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm')
22-
await installPackage(context, packageManager, null, packageName)
32+
await installPackage(context, packageManager, null, packageName, !internalPlugin)
2333

2434
stopSpinner()
2535

@@ -30,6 +40,10 @@ async function add (pluginName, options = {}, context = process.cwd()) {
3040
const generatorPath = resolveModule(`${packageName}/generator`, context)
3141
if (generatorPath) {
3242
invoke(pluginName, options, context)
43+
} else if (internalPlugin) {
44+
log()
45+
warn(`Internal Plugin: ${packageName} cannot modify files post creation. See https://${pluginName}.vuejs.org for instructions to add ${packageName} to your code`)
46+
log()
3347
} else {
3448
log(`Plugin ${packageName} does not have a generator to invoke`)
3549
}

0 commit comments

Comments
 (0)