From a9a8f1230702806b2bb51aff88b382d06d8d0593 Mon Sep 17 00:00:00 2001 From: Konv Suu <2583695112@qq.com> Date: Mon, 13 Nov 2023 17:53:58 +0800 Subject: [PATCH] feat: replace vite-plugin-pages by unplugin-vue-router (#43) --- README.md | 2 +- README.zh-CN.md | 2 +- auto-imports.d.ts | 36 +++++---- package.json | 2 +- pnpm-lock.yaml | 182 ++++++++------------------------------------ src/main.ts | 4 +- src/pages/README.md | 2 +- tsconfig.json | 1 - typed-router.d.ts | 143 ++++++++++++++++++++++++++++++++++ vite.config.ts | 13 +++- 10 files changed, 208 insertions(+), 179 deletions(-) create mode 100644 typed-router.d.ts diff --git a/README.md b/README.md index 0bbdc55f..425c11cc 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ See [Vitesse](https://github.com/antfu/vitesse) for full featureset. ### Plugins - [Vue Router](https://github.com/vuejs/vue-router) - - [`vite-plugin-pages`](https://github.com/hannoeru/vite-plugin-pages) - file system based routing + - [`unplugin-vue-router`](https://github.com/posva/unplugin-vue-router) - file system based routing - [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import) - Directly use Vue Composition API and others without importing - [`unplugin-vue-components`](https://github.com/antfu/unplugin-vue-components) - components auto import - [`unplugin-vue-macros`](https://github.com/sxzz/unplugin-vue-macros) - Explore and extend more macros and syntax sugar to Vue. diff --git a/README.zh-CN.md b/README.zh-CN.md index 4256c2f3..665d35c8 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -64,7 +64,7 @@ ### 插件 - [Vue Router](https://github.com/vuejs/vue-router) - - [`vite-plugin-pages`](https://github.com/hannoeru/vite-plugin-pages) - 以文件系统为基础的路由 + - [`unplugin-vue-router`](https://github.com/posva/unplugin-vue-router) - 以文件系统为基础的路由 - [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import) - 直接使用 Composition API 等,无需导入 - [`unplugin-vue-components`](https://github.com/antfu/unplugin-vue-components) - 自动加载组件 - [`unplugin-vue-macros`](https://github.com/sxzz/unplugin-vue-macros) - 探索并扩展更多的宏和语法糖到 Vue 中 diff --git a/auto-imports.d.ts b/auto-imports.d.ts index a4a8df90..bd15f291 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -29,6 +29,8 @@ declare global { const debouncedWatch: typeof import('@vueuse/core')['debouncedWatch'] const defineAsyncComponent: typeof import('vue')['defineAsyncComponent'] const defineComponent: typeof import('vue')['defineComponent'] + const defineLoader: typeof import('vue-router/auto')['defineLoader'] + const definePage: typeof import('unplugin-vue-router/runtime')['_definePage'] const eagerComputed: typeof import('@vueuse/core')['eagerComputed'] const effectScope: typeof import('vue')['effectScope'] const extendRef: typeof import('@vueuse/core')['extendRef'] @@ -49,8 +51,8 @@ declare global { const nextTick: typeof import('vue')['nextTick'] const onActivated: typeof import('vue')['onActivated'] const onBeforeMount: typeof import('vue')['onBeforeMount'] - const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave'] - const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate'] + const onBeforeRouteLeave: typeof import('vue-router/auto')['onBeforeRouteLeave'] + const onBeforeRouteUpdate: typeof import('vue-router/auto')['onBeforeRouteUpdate'] const onBeforeUnmount: typeof import('vue')['onBeforeUnmount'] const onBeforeUpdate: typeof import('vue')['onBeforeUpdate'] const onClickOutside: typeof import('@vueuse/core')['onClickOutside'] @@ -182,7 +184,7 @@ declare global { const useIntervalFn: typeof import('@vueuse/core')['useIntervalFn'] const useKeyModifier: typeof import('@vueuse/core')['useKeyModifier'] const useLastChanged: typeof import('@vueuse/core')['useLastChanged'] - const useLink: typeof import('vue-router')['useLink'] + const useLink: typeof import('vue-router/auto')['useLink'] const useLocalStorage: typeof import('@vueuse/core')['useLocalStorage'] const useMagicKeys: typeof import('@vueuse/core')['useMagicKeys'] const useManualRefHistory: typeof import('@vueuse/core')['useManualRefHistory'] @@ -218,8 +220,8 @@ declare global { const useRafFn: typeof import('@vueuse/core')['useRafFn'] const useRefHistory: typeof import('@vueuse/core')['useRefHistory'] const useResizeObserver: typeof import('@vueuse/core')['useResizeObserver'] - const useRoute: typeof import('vue-router')['useRoute'] - const useRouter: typeof import('vue-router')['useRouter'] + const useRoute: typeof import('vue-router/auto')['useRoute'] + const useRouter: typeof import('vue-router/auto')['useRouter'] const useScreenOrientation: typeof import('@vueuse/core')['useScreenOrientation'] const useScreenSafeArea: typeof import('@vueuse/core')['useScreenSafeArea'] const useScriptTag: typeof import('@vueuse/core')['useScriptTag'] @@ -318,6 +320,8 @@ declare module 'vue' { readonly debouncedWatch: UnwrapRef readonly defineAsyncComponent: UnwrapRef readonly defineComponent: UnwrapRef + readonly defineLoader: UnwrapRef + readonly definePage: UnwrapRef readonly eagerComputed: UnwrapRef readonly effectScope: UnwrapRef readonly extendRef: UnwrapRef @@ -338,8 +342,8 @@ declare module 'vue' { readonly nextTick: UnwrapRef readonly onActivated: UnwrapRef readonly onBeforeMount: UnwrapRef - readonly onBeforeRouteLeave: UnwrapRef - readonly onBeforeRouteUpdate: UnwrapRef + readonly onBeforeRouteLeave: UnwrapRef + readonly onBeforeRouteUpdate: UnwrapRef readonly onBeforeUnmount: UnwrapRef readonly onBeforeUpdate: UnwrapRef readonly onClickOutside: UnwrapRef @@ -471,7 +475,7 @@ declare module 'vue' { readonly useIntervalFn: UnwrapRef readonly useKeyModifier: UnwrapRef readonly useLastChanged: UnwrapRef - readonly useLink: UnwrapRef + readonly useLink: UnwrapRef readonly useLocalStorage: UnwrapRef readonly useMagicKeys: UnwrapRef readonly useManualRefHistory: UnwrapRef @@ -507,8 +511,8 @@ declare module 'vue' { readonly useRafFn: UnwrapRef readonly useRefHistory: UnwrapRef readonly useResizeObserver: UnwrapRef - readonly useRoute: UnwrapRef - readonly useRouter: UnwrapRef + readonly useRoute: UnwrapRef + readonly useRouter: UnwrapRef readonly useScreenOrientation: UnwrapRef readonly useScreenSafeArea: UnwrapRef readonly useScriptTag: UnwrapRef @@ -601,6 +605,8 @@ declare module '@vue/runtime-core' { readonly debouncedWatch: UnwrapRef readonly defineAsyncComponent: UnwrapRef readonly defineComponent: UnwrapRef + readonly defineLoader: UnwrapRef + readonly definePage: UnwrapRef readonly eagerComputed: UnwrapRef readonly effectScope: UnwrapRef readonly extendRef: UnwrapRef @@ -621,8 +627,8 @@ declare module '@vue/runtime-core' { readonly nextTick: UnwrapRef readonly onActivated: UnwrapRef readonly onBeforeMount: UnwrapRef - readonly onBeforeRouteLeave: UnwrapRef - readonly onBeforeRouteUpdate: UnwrapRef + readonly onBeforeRouteLeave: UnwrapRef + readonly onBeforeRouteUpdate: UnwrapRef readonly onBeforeUnmount: UnwrapRef readonly onBeforeUpdate: UnwrapRef readonly onClickOutside: UnwrapRef @@ -754,7 +760,7 @@ declare module '@vue/runtime-core' { readonly useIntervalFn: UnwrapRef readonly useKeyModifier: UnwrapRef readonly useLastChanged: UnwrapRef - readonly useLink: UnwrapRef + readonly useLink: UnwrapRef readonly useLocalStorage: UnwrapRef readonly useMagicKeys: UnwrapRef readonly useManualRefHistory: UnwrapRef @@ -790,8 +796,8 @@ declare module '@vue/runtime-core' { readonly useRafFn: UnwrapRef readonly useRefHistory: UnwrapRef readonly useResizeObserver: UnwrapRef - readonly useRoute: UnwrapRef - readonly useRouter: UnwrapRef + readonly useRoute: UnwrapRef + readonly useRouter: UnwrapRef readonly useScreenOrientation: UnwrapRef readonly useScreenSafeArea: UnwrapRef readonly useScriptTag: UnwrapRef diff --git a/package.json b/package.json index 2efbdf1d..8566813a 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ "unplugin-auto-import": "^0.16.7", "unplugin-vue-components": "^0.25.2", "unplugin-vue-macros": "^2.6.2", + "unplugin-vue-router": "^0.7.0", "vite": "^4.5.0", - "vite-plugin-pages": "^0.31.0", "vitest": "^0.34.6", "vue-tsc": "^1.8.22" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a1a7586..e6076d94 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -79,12 +79,12 @@ devDependencies: unplugin-vue-macros: specifier: ^2.6.2 version: 2.6.2(@vueuse/core@10.5.0)(typescript@5.2.2)(vite@4.5.0)(vue@3.3.7) + unplugin-vue-router: + specifier: ^0.7.0 + version: 0.7.0(vue-router@4.2.5)(vue@3.3.7) vite: specifier: ^4.5.0 version: 4.5.0(@types/node@20.8.10) - vite-plugin-pages: - specifier: ^0.31.0 - version: 0.31.0(vite@4.5.0) vitest: specifier: ^0.34.6 version: 0.34.6(jsdom@22.1.0) @@ -825,12 +825,6 @@ packages: resolution: {integrity: sha512-69TtiDzu0bcmKQv3yg1Zx409/Kd7r0b5F1PfpYJfSHzLGtB53547V4u+9iqKYsTu/O2ai6KTb0TInNpvuQ3qmg==} dev: true - /@types/debug@4.1.10: - resolution: {integrity: sha512-tOSCru6s732pofZ+sMv9o4o3Zc+Sa8l3bxd/tweTQudFn06vAzb13ZX46Zi6m6EJ+RUbRTHvgQJ1gBtSgkaUYA==} - dependencies: - '@types/ms': 0.7.33 - dev: true - /@types/estree@1.0.4: resolution: {integrity: sha512-2JwWnHK9H+wUZNorf2Zr6ves96WHoWDJIftkcxPKsS7Djta6Zu519LarhRNljPXkpsZR2ZMwNCPeW7omW07BJw==} dev: true @@ -845,10 +839,6 @@ packages: '@types/unist': 2.0.9 dev: true - /@types/ms@0.7.33: - resolution: {integrity: sha512-AuHIyzR5Hea7ij0P9q7vx7xu4z0C28ucwjAZC0ja7JhINyCnOw8/DnvAPQQ9TfOlCtZAmCERKQX9+o1mgQhuOQ==} - dev: true - /@types/node@20.8.10: resolution: {integrity: sha512-TlgT8JntpcbmKUFzjhsyhGfP2fsiz1Mv56im6enJ905xG1DAYesxJaeSbGqQmAw8OWPdhyJGhGSQGKRNJ45u9w==} dependencies: @@ -1718,7 +1708,6 @@ packages: /@vue/devtools-api@6.5.1: resolution: {integrity: sha512-+KpckaAQyfbvshdDW5xQylLni1asvNSGme1JFs8I1+/H5pHEhqUKMEQD/qn3Nx5+/nycBq11qAEi8lk+LXI2dA==} - dev: false /@vue/language-core@1.8.22(typescript@5.2.2): resolution: {integrity: sha512-bsMoJzCrXZqGsxawtUea1cLjUT9dZnDsy5TuZ+l1fxRMzUGQUG9+Ypq4w//CqpWmrx7nIAJpw2JVF/t258miRw==} @@ -2397,29 +2386,6 @@ packages: type-detect: 4.0.8 dev: true - /deep-equal@2.2.2: - resolution: {integrity: sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==} - dependencies: - array-buffer-byte-length: 1.0.0 - call-bind: 1.0.5 - es-get-iterator: 1.1.3 - get-intrinsic: 1.2.2 - is-arguments: 1.1.1 - is-array-buffer: 3.0.2 - is-date-object: 1.0.5 - is-regex: 1.1.4 - is-shared-array-buffer: 1.0.2 - isarray: 2.0.5 - object-is: 1.1.5 - object-keys: 1.1.1 - object.assign: 4.1.4 - regexp.prototype.flags: 1.5.1 - side-channel: 1.0.4 - which-boxed-primitive: 1.0.2 - which-collection: 1.0.1 - which-typed-array: 1.1.13 - dev: true - /deep-is@0.1.4: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} dev: true @@ -2621,20 +2587,6 @@ packages: which-typed-array: 1.1.13 dev: true - /es-get-iterator@1.1.3: - resolution: {integrity: sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==} - dependencies: - call-bind: 1.0.5 - get-intrinsic: 1.2.2 - has-symbols: 1.0.3 - is-arguments: 1.1.1 - is-map: 2.0.2 - is-set: 2.0.2 - is-string: 1.0.7 - isarray: 2.0.5 - stop-iteration-iterator: 1.0.0 - dev: true - /es-set-tostringtag@2.0.2: resolution: {integrity: sha512-BuDyupZt65P9D2D2vA/zqcI3G5xRsklm5N3xCwuiy+/vKy8i0ifdsQP1sLgO4tZDSCaQUSnmC48khknGMV3D2Q==} engines: {node: '>= 0.4'} @@ -3083,19 +3035,6 @@ packages: eslint-visitor-keys: 3.4.3 dev: true - /esprima-extract-comments@1.1.0: - resolution: {integrity: sha512-sBQUnvJwpeE9QnPrxh7dpI/dp67erYG4WXEAreAMoelPRpMR7NWb4YtwRPn9b+H1uLQKl/qS8WYmyaljTpjIsw==} - engines: {node: '>=4'} - dependencies: - esprima: 4.0.1 - dev: true - - /esprima@4.0.1: - resolution: {integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==} - engines: {node: '>=4'} - hasBin: true - dev: true - /esquery@1.5.0: resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==} engines: {node: '>=0.10'} @@ -3176,14 +3115,6 @@ packages: resolution: {integrity: sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==} dev: true - /extract-comments@1.1.0: - resolution: {integrity: sha512-dzbZV2AdSSVW/4E7Ti5hZdHWbA+Z80RJsJhr5uiL10oyjl/gy7/o+HI1HwK4/WSZhlq4SNKU3oUzXlM13Qx02Q==} - engines: {node: '>=6'} - dependencies: - esprima-extract-comments: 1.1.0 - parse-code-context: 1.0.0 - dev: true - /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} dev: true @@ -3668,14 +3599,6 @@ packages: is-decimal: 1.0.4 dev: true - /is-arguments@1.1.1: - resolution: {integrity: sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.5 - has-tostringtag: 1.0.0 - dev: true - /is-array-buffer@3.0.2: resolution: {integrity: sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w==} dependencies: @@ -3788,10 +3711,6 @@ packages: resolution: {integrity: sha512-z7CMFGNrENq5iFB9Bqo64Xk6Y9sg+epq1myIcdHaGnbMTYOxvzsEtdYqQUylB7LxfkvgrrjP32T6Ywciio9UIQ==} dev: true - /is-map@2.0.2: - resolution: {integrity: sha512-cOZFQQozTha1f4MxLFzlgKYPTyj26picdZTx82hbc/Xf4K/tZOOXSCkMvU4pKioRXGDLJRn0GM7Upe7kR721yg==} - dev: true - /is-negative-zero@2.0.2: resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} engines: {node: '>= 0.4'} @@ -3826,10 +3745,6 @@ packages: has-tostringtag: 1.0.0 dev: true - /is-set@2.0.2: - resolution: {integrity: sha512-+2cnTEZeY5z/iXGbLhPrOAaK/Mau5k5eXq9j14CpRTftq0pAJu2MwVRSZhyZWBzx3o6X795Lz6Bpb6R0GKf37g==} - dev: true - /is-shared-array-buffer@1.0.2: resolution: {integrity: sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==} dependencies: @@ -3867,23 +3782,12 @@ packages: which-typed-array: 1.1.13 dev: true - /is-weakmap@2.0.1: - resolution: {integrity: sha512-NSBR4kH5oVj1Uwvv970ruUkCV7O1mzgVFO4/rev2cLRda9Tm9HrL70ZPut4rOHgY0FNrUu9BCbXA2sdQ+x0chA==} - dev: true - /is-weakref@1.0.2: resolution: {integrity: sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==} dependencies: call-bind: 1.0.5 dev: true - /is-weakset@2.0.2: - resolution: {integrity: sha512-t2yVvttHkQktwnNNmBQ98AhENLdPUTDTE21uPqAQ0ARwQfGeQKRVS0NNurH7bTf7RrvcVn1OOge45CnBeHCSmg==} - dependencies: - call-bind: 1.0.5 - get-intrinsic: 1.2.2 - dev: true - /is-wsl@2.2.0: resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} engines: {node: '>=8'} @@ -4582,14 +4486,6 @@ packages: resolution: {integrity: sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==} dev: true - /object-is@1.1.5: - resolution: {integrity: sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==} - engines: {node: '>= 0.4'} - dependencies: - call-bind: 1.0.5 - define-properties: 1.2.1 - dev: true - /object-keys@1.1.1: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} engines: {node: '>= 0.4'} @@ -4746,11 +4642,6 @@ packages: callsites: 3.1.0 dev: true - /parse-code-context@1.0.0: - resolution: {integrity: sha512-OZQaqKaQnR21iqhlnPfVisFjBWjhnMl5J9MgbP8xC+EwoVqbXrq78lp+9Zb3ahmLzrIX5Us/qbvBnaS3hkH6OA==} - engines: {node: '>=6'} - dev: true - /parse-entities@2.0.0: resolution: {integrity: sha512-kkywGpCcRYhqQIchaWqZ875wzpS/bMKhz5HnN3p7wveJTkTtyAB/AlnS0f8DFSqYW1T82t6yEAkEcB+A1I3MbQ==} dependencies: @@ -5312,13 +5203,6 @@ packages: resolution: {integrity: sha512-f9aPhy8fYBuMN+sNfakZV18U39PbalgjXG3lLB9WkaYTxijru61wb57V9wxxNthXM5Sd88ETBWi29qLAsHO52Q==} dev: true - /stop-iteration-iterator@1.0.0: - resolution: {integrity: sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==} - engines: {node: '>= 0.4'} - dependencies: - internal-slot: 1.0.6 - dev: true - /string-argv@0.3.2: resolution: {integrity: sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==} engines: {node: '>=0.6.19'} @@ -5869,6 +5753,33 @@ packages: - webpack dev: true + /unplugin-vue-router@0.7.0(vue-router@4.2.5)(vue@3.3.7): + resolution: {integrity: sha512-ddRreGq0t5vlSB7OMy4e4cfU1w2AwBQCwmvW3oP/0IHQiokzbx4hd3TpwBu3eIAFVuhX2cwNQwp1U32UybTVCw==} + peerDependencies: + vue-router: ^4.1.0 + peerDependenciesMeta: + vue-router: + optional: true + dependencies: + '@babel/types': 7.23.0 + '@rollup/pluginutils': 5.0.5(rollup@3.29.4) + '@vue-macros/common': 1.8.0(rollup@3.29.4)(vue@3.3.7) + ast-walker-scope: 0.5.0 + chokidar: 3.5.3 + fast-glob: 3.3.1 + json5: 2.2.3 + local-pkg: 0.4.3 + mlly: 1.4.2 + pathe: 1.1.1 + scule: 1.0.0 + unplugin: 1.5.0 + vue-router: 4.2.5(vue@3.3.7) + yaml: 2.3.3 + transitivePeerDependencies: + - rollup + - vue + dev: true + /unplugin@1.5.0: resolution: {integrity: sha512-9ZdRwbh/4gcm1JTOkp9lAkIDrtOyOxgHmY7cjuwI8L/2RTikMcVG25GsZwNAgRuap3iDw2jeq7eoqtAsz5rW3A==} dependencies: @@ -5936,29 +5847,6 @@ packages: - terser dev: true - /vite-plugin-pages@0.31.0(vite@4.5.0): - resolution: {integrity: sha512-fw3onBfVTXQI7rOzAbSZhmfwvk50+3qNnGZpERjmD93c8nEjrGLyd53eFXYMxcJV4KA1vzi4qIHt2+6tS4dEMw==} - peerDependencies: - '@vue/compiler-sfc': ^2.7.0 || ^3.0.0 - vite: ^2.0.0 || ^3.0.0-0 || ^4.0.0 - peerDependenciesMeta: - '@vue/compiler-sfc': - optional: true - dependencies: - '@types/debug': 4.1.10 - debug: 4.3.4 - deep-equal: 2.2.2 - extract-comments: 1.1.0 - fast-glob: 3.3.1 - json5: 2.2.3 - local-pkg: 0.4.3 - picocolors: 1.0.0 - vite: 4.5.0(@types/node@20.8.10) - yaml: 2.3.3 - transitivePeerDependencies: - - supports-color - dev: true - /vite@4.5.0(@types/node@20.8.10): resolution: {integrity: sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==} engines: {node: ^14.18.0 || >=16.0.0} @@ -6104,7 +5992,6 @@ packages: dependencies: '@vue/devtools-api': 6.5.1 vue: 3.3.7(typescript@5.2.2) - dev: false /vue-template-compiler@2.7.15: resolution: {integrity: sha512-yQxjxMptBL7UAog00O8sANud99C6wJF+7kgbcwqkvA38vCGF7HWE66w0ZFnS/kX5gSoJr/PQ4/oS3Ne2pW37Og==} @@ -6195,15 +6082,6 @@ packages: is-symbol: 1.0.4 dev: true - /which-collection@1.0.1: - resolution: {integrity: sha512-W8xeTUwaln8i3K/cY1nGXzdnVZlidBcagyNFtBdD5kxnb4TvGKR7FfSIS3mYpwWS1QUCutfKz8IY8RjftB0+1A==} - dependencies: - is-map: 2.0.2 - is-set: 2.0.2 - is-weakmap: 2.0.1 - is-weakset: 2.0.2 - dev: true - /which-typed-array@1.1.13: resolution: {integrity: sha512-P5Nra0qjSncduVPEAr7xhoF5guty49ArDTwzJ/yNuPIbZppyRxFQsRCWrocxIY+CnMVG+qfbU2FmDKyvSGClow==} engines: {node: '>= 0.4'} diff --git a/src/main.ts b/src/main.ts index e110b673..da402176 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,5 @@ import { createApp } from 'vue' -import { createRouter, createWebHistory } from 'vue-router' -import routes from 'virtual:generated-pages' +import { createRouter, createWebHistory } from 'vue-router/auto' import App from './App.vue' import '@unocss/reset/tailwind.css' @@ -10,7 +9,6 @@ import 'uno.css' const app = createApp(App) const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), - routes, }) app.use(router) app.mount('#app') diff --git a/src/pages/README.md b/src/pages/README.md index 929b7c9d..26b343d7 100644 --- a/src/pages/README.md +++ b/src/pages/README.md @@ -1,7 +1,7 @@ ## File-based Routing Routes will be auto-generated for Vue files in this dir with the same file structure. -Check out [`vite-plugin-pages`](https://github.com/hannoeru/vite-plugin-pages) for more details. +Check out [`unplugin-vue-router`](https://github.com/posva/unplugin-vue-router) for more details. ### Path Aliasing diff --git a/tsconfig.json b/tsconfig.json index 2ac99bba..e628a53e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,6 @@ "resolveJsonModule": true, "types": [ "vite/client", - "vite-plugin-pages/client", "unplugin-vue-macros/macros-global" ], "allowJs": true, diff --git a/typed-router.d.ts b/typed-router.d.ts new file mode 100644 index 00000000..7152731b --- /dev/null +++ b/typed-router.d.ts @@ -0,0 +1,143 @@ +/* eslint-disable */ +/* prettier-ignore */ +// @ts-nocheck +// Generated by unplugin-vue-router. ‼️ DO NOT MODIFY THIS FILE ‼️ +// It's recommended to commit this file. +// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry. + +/// + +import type { + // type safe route locations + RouteLocationTypedList, + RouteLocationResolvedTypedList, + RouteLocationNormalizedTypedList, + RouteLocationNormalizedLoadedTypedList, + RouteLocationAsString, + RouteLocationAsRelativeTypedList, + RouteLocationAsPathTypedList, + + // helper types + // route definitions + RouteRecordInfo, + ParamValue, + ParamValueOneOrMore, + ParamValueZeroOrMore, + ParamValueZeroOrOne, + + // vue-router extensions + _RouterTyped, + RouterLinkTyped, + RouterLinkPropsTyped, + NavigationGuard, + UseLinkFnTyped, + + // data fetching + _DataLoader, + _DefineLoaderOptions, +} from 'unplugin-vue-router/types' + +declare module 'vue-router/auto/routes' { + export interface RouteNamedMap { + '/': RouteRecordInfo<'/', '/', Record, Record>, + '/[...all]': RouteRecordInfo<'/[...all]', '/:all(.*)', { all: ParamValue }, { all: ParamValue }>, + '/hi/[name]': RouteRecordInfo<'/hi/[name]', '/hi/:name', { name: ParamValue }, { name: ParamValue }>, + } +} + +declare module 'vue-router/auto' { + import type { RouteNamedMap } from 'vue-router/auto/routes' + + export type RouterTyped = _RouterTyped + + /** + * Type safe version of `RouteLocationNormalized` (the type of `to` and `from` in navigation guards). + * Allows passing the name of the route to be passed as a generic. + */ + export type RouteLocationNormalized = RouteLocationNormalizedTypedList[Name] + + /** + * Type safe version of `RouteLocationNormalizedLoaded` (the return type of `useRoute()`). + * Allows passing the name of the route to be passed as a generic. + */ + export type RouteLocationNormalizedLoaded = RouteLocationNormalizedLoadedTypedList[Name] + + /** + * Type safe version of `RouteLocationResolved` (the returned route of `router.resolve()`). + * Allows passing the name of the route to be passed as a generic. + */ + export type RouteLocationResolved = RouteLocationResolvedTypedList[Name] + + /** + * Type safe version of `RouteLocation` . Allows passing the name of the route to be passed as a generic. + */ + export type RouteLocation = RouteLocationTypedList[Name] + + /** + * Type safe version of `RouteLocationRaw` . Allows passing the name of the route to be passed as a generic. + */ + export type RouteLocationRaw = + | RouteLocationAsString + | RouteLocationAsRelativeTypedList[Name] + | RouteLocationAsPathTypedList[Name] + + /** + * Generate a type safe params for a route location. Requires the name of the route to be passed as a generic. + */ + export type RouteParams = RouteNamedMap[Name]['params'] + /** + * Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic. + */ + export type RouteParamsRaw = RouteNamedMap[Name]['paramsRaw'] + + export function useRouter(): RouterTyped + export function useRoute(name?: Name): RouteLocationNormalizedLoadedTypedList[Name] + + export const useLink: UseLinkFnTyped + + export function onBeforeRouteLeave(guard: NavigationGuard): void + export function onBeforeRouteUpdate(guard: NavigationGuard): void + + export const RouterLink: RouterLinkTyped + export const RouterLinkProps: RouterLinkPropsTyped + + // Experimental Data Fetching + + export function defineLoader< + P extends Promise, + Name extends keyof RouteNamedMap = keyof RouteNamedMap, + isLazy extends boolean = false, + >( + name: Name, + loader: (route: RouteLocationNormalizedLoaded) => P, + options?: _DefineLoaderOptions, + ): _DataLoader, isLazy> + export function defineLoader< + P extends Promise, + isLazy extends boolean = false, + >( + loader: (route: RouteLocationNormalizedLoaded) => P, + options?: _DefineLoaderOptions, + ): _DataLoader, isLazy> + + export { + _definePage as definePage, + _HasDataLoaderMeta as HasDataLoaderMeta, + _setupDataFetchingGuard as setupDataFetchingGuard, + _stopDataFetchingScope as stopDataFetchingScope, + } from 'unplugin-vue-router/runtime' +} + +declare module 'vue-router' { + import type { RouteNamedMap } from 'vue-router/auto/routes' + + export interface TypesConfig { + beforeRouteUpdate: NavigationGuard + beforeRouteLeave: NavigationGuard + + $route: RouteLocationNormalizedLoadedTypedList[keyof RouteNamedMap] + $router: _RouterTyped + + RouterLink: RouterLinkTyped + } +} diff --git a/vite.config.ts b/vite.config.ts index 1786f707..b739a5f8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,11 +3,12 @@ import path from 'node:path' import { defineConfig } from 'vite' import Vue from '@vitejs/plugin-vue' -import Pages from 'vite-plugin-pages' import Components from 'unplugin-vue-components/vite' import AutoImport from 'unplugin-auto-import/vite' import UnoCSS from 'unocss/vite' import VueMacros from 'unplugin-vue-macros/vite' +import VueRouter from 'unplugin-vue-router/vite' +import { VueRouterAutoImports } from 'unplugin-vue-router' export default defineConfig({ resolve: { @@ -29,15 +30,19 @@ export default defineConfig({ }, }), - // https://github.com/hannoeru/vite-plugin-pages - Pages(), + // https://github.com/posva/unplugin-vue-router + VueRouter(), // https://github.com/antfu/unplugin-auto-import AutoImport({ imports: [ 'vue', - 'vue-router', '@vueuse/core', + VueRouterAutoImports, + { + // add any other imports you were relying on + 'vue-router/auto': ['useLink'], + }, ], dts: true, dirs: [