diff --git a/.eslintignore b/.eslintignore index 0af0fe5..8a135aa 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ /generator/template +/generator/template-vue3 node_modules \ No newline at end of file diff --git a/generator/index.js b/generator/index.js index 325ae29..a884247 100644 --- a/generator/index.js +++ b/generator/index.js @@ -1,7 +1,10 @@ -module.exports = (api) => { +/* eslint-disable-next-line no-unused-vars */ +module.exports = (api, _options = {}, rootOptions = {}) => { + const isVue3 = rootOptions.vueVersion === '3' + api.extendPackage({ dependencies: { - 'vue-router-layout': '^0.2.0', + 'vue-router-layout': isVue3 ? '^0.2.0' : '^0.1.2', }, devDependencies: { 'vue-auto-routing': '^1.0.0', @@ -17,6 +20,10 @@ module.exports = (api) => { api.render('./template') + if (isVue3) { + api.render('./template-vue3') + } + if (api.invoking) { api.postProcessFiles((files) => { Object.keys(files).forEach((name) => { diff --git a/generator/template-vue3/src/router/index.js b/generator/template-vue3/src/router/index.js new file mode 100644 index 0000000..5289d5a --- /dev/null +++ b/generator/template-vue3/src/router/index.js @@ -0,0 +1,20 @@ +import { createRouter, createWebHistory } from 'vue-router' +import routes from 'vue-auto-routing' +import { createRouterLayout } from 'vue-router-layout' + +const RouterLayout = createRouterLayout(layout => { + return import('@/layouts/' + layout + '.vue') +}) + +const router = createRouter({ + history: createWebHistory(process.env.BASE_URL), + routes: [ + { + path: '/', + component: RouterLayout, + children: routes + } + ] +}) + +export default router diff --git a/generator/template/src/router/index.js b/generator/template/src/router/index.js index 3806b66..2d52790 100644 --- a/generator/template/src/router/index.js +++ b/generator/template/src/router/index.js @@ -10,7 +10,7 @@ const RouterLayout = createRouterLayout(layout => { }) export default new Router({ - mode: "history", + mode: 'history', base: process.env.BASE_URL, routes: [ {