Skip to content

Commit dc318c5

Browse files
authored
fix: add a compatibility layer for router & vuex for CLI v3 (#4693)
fixes #4691
1 parent 14ec578 commit dc318c5

File tree

1 file changed

+39
-0
lines changed
  • packages/@vue/cli-service/generator

1 file changed

+39
-0
lines changed

packages/@vue/cli-service/generator/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { execa } = require('@vue/cli-shared-utils')
2+
13
module.exports = (api, options) => {
24
api.render('./template', {
35
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
@@ -54,6 +56,43 @@ module.exports = (api, options) => {
5456
})
5557
}
5658

59+
// for v3 compatibility
60+
if (options.router && !api.hasPlugin('router')) {
61+
api.extendPackage({
62+
devDependencies: {
63+
'@vue/cli-plugin-router': '^4.0.0'
64+
}
65+
})
66+
67+
api.onCreateComplete(() => {
68+
execa.sync('vue', [
69+
'invoke',
70+
'@vue/cli-plugin-router',
71+
`--historyMode=${options.routerHistoryMode ? 'true' : ''}`
72+
], {
73+
cwd: api.resolve('.')
74+
})
75+
})
76+
}
77+
78+
// for v3 compatibility
79+
if (options.vuex && !api.hasPlugin('vuex')) {
80+
api.extendPackage({
81+
devDependencies: {
82+
'@vue/cli-plugin-vuex': '^4.0.0'
83+
}
84+
})
85+
86+
api.onCreateComplete(() => {
87+
execa.sync('vue', [
88+
'invoke',
89+
'@vue/cli-plugin-vuex'
90+
], {
91+
cwd: api.resolve('.')
92+
})
93+
})
94+
}
95+
5796
// additional tooling configurations
5897
if (options.configs) {
5998
api.extendPackage(options.configs)

0 commit comments

Comments
 (0)