Skip to content

Commit

Permalink
fix: add a compatibility layer for router & vuex for CLI v3 (#4693)
Browse files Browse the repository at this point in the history
fixes #4691
  • Loading branch information
sodatea committed Oct 17, 2019
1 parent 14ec578 commit dc318c5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/@vue/cli-service/generator/index.js
@@ -1,3 +1,5 @@
const { execa } = require('@vue/cli-shared-utils')

module.exports = (api, options) => {
api.render('./template', {
doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
Expand Down Expand Up @@ -54,6 +56,43 @@ module.exports = (api, options) => {
})
}

// for v3 compatibility
if (options.router && !api.hasPlugin('router')) {
api.extendPackage({
devDependencies: {
'@vue/cli-plugin-router': '^4.0.0'
}
})

api.onCreateComplete(() => {
execa.sync('vue', [
'invoke',
'@vue/cli-plugin-router',
`--historyMode=${options.routerHistoryMode ? 'true' : ''}`
], {
cwd: api.resolve('.')
})
})
}

// for v3 compatibility
if (options.vuex && !api.hasPlugin('vuex')) {
api.extendPackage({
devDependencies: {
'@vue/cli-plugin-vuex': '^4.0.0'
}
})

api.onCreateComplete(() => {
execa.sync('vue', [
'invoke',
'@vue/cli-plugin-vuex'
], {
cwd: api.resolve('.')
})
})
}

// additional tooling configurations
if (options.configs) {
api.extendPackage(options.configs)
Expand Down

0 comments on commit dc318c5

Please sign in to comment.