index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. module.exports = (api, options = {}, rootOptions = {}) => {
  2. const isVue3 = (rootOptions.vueVersion === '3')
  3. api.injectImports(api.entryFile, `import router from './router'`)
  4. if (isVue3) {
  5. api.transformScript(api.entryFile, require('./injectUseRouter'))
  6. api.extendPackage({
  7. dependencies: {
  8. 'vue-router': '^4.0.3'
  9. }
  10. })
  11. } else {
  12. api.injectRootOptions(api.entryFile, `router`)
  13. api.extendPackage({
  14. dependencies: {
  15. 'vue-router': '^3.5.1'
  16. }
  17. })
  18. }
  19. api.render('./template', {
  20. historyMode: options.historyMode,
  21. doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript'),
  22. hasTypeScript: api.hasPlugin('typescript')
  23. })
  24. if (isVue3) {
  25. api.render('./template-vue3', {
  26. historyMode: options.historyMode,
  27. doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript'),
  28. hasTypeScript: api.hasPlugin('typescript')
  29. })
  30. }
  31. if (api.invoking) {
  32. if (api.hasPlugin('typescript')) {
  33. /* eslint-disable-next-line node/no-extraneous-require */
  34. const convertFiles = require('@vue/cli-plugin-typescript/generator/convert')
  35. convertFiles(api)
  36. }
  37. }
  38. }