index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module.exports = (api, options = {}) => {
  2. api.injectImports(api.entryFile, `import router from './router'`)
  3. api.injectRootOptions(api.entryFile, `router`)
  4. api.extendPackage({
  5. dependencies: {
  6. 'vue-router': '^3.0.3'
  7. }
  8. })
  9. api.render('./template', {
  10. historyMode: options.routerHistoryMode,
  11. doesCompile: api.hasPlugin('babel') || api.hasPlugin('typescript')
  12. })
  13. if (api.invoking) {
  14. api.postProcessFiles(files => {
  15. const appFile = files[`src/App.vue`]
  16. if (appFile) {
  17. files[`src/App.vue`] = appFile.replace(/^<template>[^]+<\/script>/, `
  18. <template>
  19. <div id="app">
  20. <div id="nav">
  21. <router-link to="/">Home</router-link> |
  22. <router-link to="/about">About</router-link>
  23. </div>
  24. <router-view/>
  25. </div>
  26. </template>
  27. `.trim())
  28. }
  29. })
  30. if (api.hasPlugin('typescript')) {
  31. /* eslint-disable-next-line node/no-extraneous-require */
  32. const convertFiles = require('@vue/cli-plugin-typescript/generator/convert')
  33. convertFiles(api)
  34. }
  35. }
  36. }