diff --git a/layout/index.ejs b/layout/index.ejs index e7bf49d8..0ea2dc10 100644 --- a/layout/index.ejs +++ b/layout/index.ejs @@ -1 +1 @@ -
\ No newline at end of file +
\ No newline at end of file diff --git a/package.json b/package.json index 060aee87..0cbcecb3 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "typescript": "~5.1.5", "vite": "^4.3.9", "vite-plugin-html-transformer": "^4.0.0", + "vite-plugin-pages": "^0.31.0", "vite-plugin-svg-icons": "^2.0.1", "vue-easy-lightbox": "^1.16.0", "vue-jest": "^3.0.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ce791f9f..1c86586a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -121,6 +121,9 @@ devDependencies: vite-plugin-html-transformer: specifier: ^4.0.0 version: 4.0.0(vite@4.3.9) + vite-plugin-pages: + specifier: ^0.31.0 + version: 0.31.0(vite@4.3.9) vite-plugin-svg-icons: specifier: ^2.0.1 version: 2.0.1(vite@4.3.9) @@ -1025,6 +1028,12 @@ packages: resolution: {integrity: sha512-lB9lMjuqjtuJrx7/kOkqQBtllspPIN+96OvTCeJ2j5FEzinoAXTdAMFnDAQT1KVPRlnYfBrqxtqP66vDM40xxQ==} dev: true + /@types/debug@4.1.8: + resolution: {integrity: sha512-/vPO1EPOs306Cvhwv7KfVfYvOJqA/S/AXjaHQiJboCZzcNDb+TIJFN9/2C9DZ//ijSKWioNyUxD792QmDJ+HKQ==} + dependencies: + '@types/ms': 0.7.31 + dev: true + /@types/estree@1.0.1: resolution: {integrity: sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==} dev: true @@ -1068,6 +1077,10 @@ packages: resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} dev: true + /@types/ms@0.7.31: + resolution: {integrity: sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==} + dev: true + /@types/node@20.3.2: resolution: {integrity: sha512-vOBLVQeCQfIcF/2Y7eKFTqrMnizK5lRNQ7ykML/5RuwVXVWxYkgwS7xbt4B6fKCUPgbSL5FSsjHQpaGQP/dQmw==} dev: true @@ -2862,6 +2875,29 @@ packages: engines: {node: '>=0.10'} 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.2 + es-get-iterator: 1.1.3 + get-intrinsic: 1.2.1 + 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.0 + side-channel: 1.0.4 + which-boxed-primitive: 1.0.2 + which-collection: 1.0.1 + which-typed-array: 1.1.9 + dev: true + /deep-extend@0.6.0: resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==} engines: {node: '>=4.0.0'} @@ -3231,6 +3267,20 @@ packages: resolution: {integrity: sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==} dev: true + /es-get-iterator@1.1.3: + resolution: {integrity: sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==} + dependencies: + call-bind: 1.0.2 + get-intrinsic: 1.2.1 + 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.1: resolution: {integrity: sha512-g3OMbtlwY3QewlqAiMLI47KywjWZoEytKr8pf6iTC8uJq5bIAH52Z9pnQ8pVL6whrCto53JZDuUIsifGeLorTg==} engines: {node: '>= 0.4'} @@ -3456,6 +3506,13 @@ packages: eslint-visitor-keys: 3.4.1 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'} @@ -3598,6 +3655,14 @@ packages: - supports-color 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 + /extract-from-css@0.4.4: resolution: {integrity: sha512-41qWGBdtKp9U7sgBxAQ7vonYqSXzgW/SiAYzq4tdWSVhAShvpVCH1nyvPQgjse6EdgbW7Y7ERdT3674/lKr65A==} engines: {node: '>=0.10.0', npm: '>=2.0.0'} @@ -4471,6 +4536,14 @@ packages: kind-of: 6.0.3 dev: true + /is-arguments@1.1.1: + resolution: {integrity: sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.2 + has-tostringtag: 1.0.0 + dev: true + /is-array-buffer@3.0.2: resolution: {integrity: sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w==} dependencies: @@ -4608,6 +4681,10 @@ packages: is-extglob: 2.1.1 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'} @@ -4662,6 +4739,10 @@ 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: @@ -4715,12 +4796,23 @@ packages: engines: {node: '>=12'} 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.2 dev: true + /is-weakset@2.0.2: + resolution: {integrity: sha512-t2yVvttHkQktwnNNmBQ98AhENLdPUTDTE21uPqAQ0ARwQfGeQKRVS0NNurH7bTf7RrvcVn1OOge45CnBeHCSmg==} + dependencies: + call-bind: 1.0.2 + get-intrinsic: 1.2.1 + dev: true + /is-windows@1.0.2: resolution: {integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==} engines: {node: '>=0.10.0'} @@ -4920,6 +5012,12 @@ packages: minimist: 1.2.8 dev: true + /json5@2.2.3: + resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==} + engines: {node: '>=6'} + hasBin: true + dev: true + /jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} dependencies: @@ -5003,6 +5101,11 @@ packages: json5: 1.0.2 dev: true + /local-pkg@0.4.3: + resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==} + engines: {node: '>=14'} + dev: true + /locate-path@2.0.0: resolution: {integrity: sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==} engines: {node: '>=4'} @@ -5783,6 +5886,14 @@ packages: resolution: {integrity: sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==} dev: true + /object-is@1.1.5: + resolution: {integrity: sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==} + engines: {node: '>= 0.4'} + dependencies: + call-bind: 1.0.2 + define-properties: 1.2.0 + dev: true + /object-keys@1.1.1: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} engines: {node: '>= 0.4'} @@ -6012,6 +6123,11 @@ packages: safe-buffer: 5.2.1 dev: true + /parse-code-context@1.0.0: + resolution: {integrity: sha512-OZQaqKaQnR21iqhlnPfVisFjBWjhnMl5J9MgbP8xC+EwoVqbXrq78lp+9Zb3ahmLzrIX5Us/qbvBnaS3hkH6OA==} + engines: {node: '>=6'} + dev: true + /parse-json@4.0.0: resolution: {integrity: sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==} engines: {node: '>=4'} @@ -7159,6 +7275,13 @@ packages: object-copy: 0.1.0 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.5 + dev: true + /stream-browserify@2.0.2: resolution: {integrity: sha512-nX6hmklHs/gr2FuxYDltq8fJA1GDlxKQCz8O/IM4atRqBH8OORmBNgfvW5gG10GT/qQ9u0CzIvr2X5Pkt6ntqg==} dependencies: @@ -7888,6 +8011,29 @@ packages: - rollup dev: true + /vite-plugin-pages@0.31.0(vite@4.3.9): + 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.8 + debug: 4.3.4 + deep-equal: 2.2.2 + extract-comments: 1.1.0 + fast-glob: 3.3.0 + json5: 2.2.3 + local-pkg: 0.4.3 + picocolors: 1.0.0 + vite: 4.3.9(@types/node@20.3.2)(sass@1.63.6) + yaml: 2.3.1 + transitivePeerDependencies: + - supports-color + dev: true + /vite-plugin-svg-icons@2.0.1(vite@4.3.9): resolution: {integrity: sha512-6ktD+DhV6Rz3VtedYvBKKVA2eXF+sAQVaKkKLDSqGUfnhqXl3bj5PPkVTl3VexfTuZy66PmINi8Q6eFnVfRUmA==} peerDependencies: @@ -8194,6 +8340,15 @@ 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.9: resolution: {integrity: sha512-w9c4xkx6mPidwp7180ckYWfMmvxpjlZuIudNtDf4N/tTAUB8VJbX25qZoAsrtGuYNnGw3pa0AXgbGKRB8/EceA==} engines: {node: '>= 0.4'} diff --git a/src/components/ArticleCard/src/Article.vue b/src/components/ArticleCard/src/Article.vue index ee047133..8f5a2476 100644 --- a/src/components/ArticleCard/src/Article.vue +++ b/src/components/ArticleCard/src/Article.vue @@ -72,7 +72,7 @@

{{ post.title }}

diff --git a/src/components/ArticleCard/src/HorizontalArticle.vue b/src/components/ArticleCard/src/HorizontalArticle.vue index 16e8cb2d..7da39e91 100644 --- a/src/components/ArticleCard/src/HorizontalArticle.vue +++ b/src/components/ArticleCard/src/HorizontalArticle.vue @@ -74,7 +74,7 @@

{{ post.title }}

diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue index 550bb8d1..762a7b1f 100644 --- a/src/components/SearchModal.vue +++ b/src/components/SearchModal.vue @@ -366,7 +366,7 @@ export default defineComponent({ reloadRecentResult() handleStatusChange(false) if (result.slug !== '') - router.push({ name: 'post', params: { slug: result.slug } }) + router.push({ name: 'post-slug', params: { slug: result.slug } }) } const handleResetInput = () => { @@ -469,9 +469,9 @@ export default defineComponent({ const initSearch = async () => { searchIndexStatus.value = false isEmpty.value = false - await searchStore.fetchSearchIndex().then(() => { - searchIndexStatus.value = true - }) + // await searchStore.fetchSearchIndex().then(() => { + // searchIndexStatus.value = true + // }) } onBeforeMount(initSearch) diff --git a/src/hooks/usePageTitle.ts b/src/hooks/usePageTitle.ts index 5bee8c3c..d047b223 100644 --- a/src/hooks/usePageTitle.ts +++ b/src/hooks/usePageTitle.ts @@ -12,13 +12,14 @@ export default function usePageTitle() { const updateTitle = (locale?: Locales | undefined) => { const currentLocale: Locales = locale ?? appStore.locale - const menuName = String(route.name) + const menuName = String(route.name === 'index' ? 'home' : route.name) const routeInfo = appStore.themeConfig.menu.menus[ menuName.charAt(0).toUpperCase() + menuName.slice(1) ] pageTitle.value = - (routeInfo.i18n && routeInfo.i18n[currentLocale]) || routeInfo.name + (routeInfo && routeInfo.i18n && routeInfo.i18n[currentLocale]) || + routeInfo.name metaStore.setTitle(pageTitle.value) } diff --git a/src/views/404.vue b/src/pages/[...all].vue similarity index 100% rename from src/views/404.vue rename to src/pages/[...all].vue diff --git a/src/views/About.vue b/src/pages/about.vue similarity index 100% rename from src/views/About.vue rename to src/pages/about.vue diff --git a/src/views/Archives.vue b/src/pages/archives.vue similarity index 98% rename from src/views/Archives.vue rename to src/pages/archives.vue index e182fc72..74b7ddb1 100644 --- a/src/views/Archives.vue +++ b/src/pages/archives.vue @@ -34,7 +34,9 @@
- +

{{ post.title }}

diff --git a/src/views/Category.vue b/src/pages/category.vue similarity index 100% rename from src/views/Category.vue rename to src/pages/category.vue diff --git a/src/views/Home.vue b/src/pages/index.vue similarity index 100% rename from src/views/Home.vue rename to src/pages/index.vue diff --git a/src/views/Links.vue b/src/pages/links.vue similarity index 100% rename from src/views/Links.vue rename to src/pages/links.vue diff --git a/src/views/Page.vue b/src/pages/page/[slug].vue similarity index 100% rename from src/views/Page.vue rename to src/pages/page/[slug].vue diff --git a/src/views/Post.vue b/src/pages/post/[slug].vue similarity index 100% rename from src/views/Post.vue rename to src/pages/post/[slug].vue diff --git a/src/views/Result.vue b/src/pages/post/search/index.vue similarity index 100% rename from src/views/Result.vue rename to src/pages/post/search/index.vue diff --git a/src/views/Tag.vue b/src/pages/tags.vue similarity index 100% rename from src/views/Tag.vue rename to src/pages/tags.vue diff --git a/src/router/index.ts b/src/router/index.ts index a0c5bcbd..afe0bb0d 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,70 +1,6 @@ /* eslint-disable */ import { createRouter, createWebHistory } from 'vue-router' -import Home from '../views/Home.vue' - -const routes = [ - { - path: '/', - name: 'home', - component: Home - }, - { - path: '/404', - name: 'not-found', - component: () => import('../views/404.vue'), - hidden: true - }, - { - path: '/about', - name: 'about', - component: () => import('../views/About.vue') - }, - { - path: '/links', - name: 'links', - component: () => import('../views/Links.vue') - }, - { - path: '/categories', - name: 'categories', - component: () => import('../views/Category.vue') - }, - { - path: '/archives', - name: 'archives', - component: () => import('../views/Archives.vue') - }, - { - path: '/tags', - name: 'tags', - component: () => import('../views/Tag.vue') - }, - { - path: '/post/search', - name: 'post-search', - component: () => import('../views/Result.vue') - }, - { - path: '/post/:slug*', - name: 'post', - component: () => import('../views/Post.vue'), - props: true - }, - { - path: '/page/:slug*', - name: 'page', - component: () => import('../views/Page.vue'), - props: true - }, - { - path: '/result', - name: 'result', - component: () => import('../views/Result.vue'), - props: true - }, - // 404 page must be placed at the end !!! - { path: '/:catchAll(.*)', redirect: '/404', hidden: true } -] +import routes from '~pages' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), diff --git a/src/shims-vue.d.ts b/src/shims-vue.d.ts index e3b39ca6..4c853ee0 100644 --- a/src/shims-vue.d.ts +++ b/src/shims-vue.d.ts @@ -1,3 +1,6 @@ +// vite-env.d.ts +/// + /* eslint-disable */ declare module '*.vue' { import type { DefineComponent } from 'vue' diff --git a/src/utils/comments/waline-api.ts b/src/utils/comments/waline-api.ts index bdf0cf64..ec6fda02 100644 --- a/src/utils/comments/waline-api.ts +++ b/src/utils/comments/waline-api.ts @@ -8,11 +8,11 @@ import { // @ts-expect-error } from 'https://unpkg.com/@waline/client@v2/dist/waline.mjs' import { cleanPath, filterHTMLContent, formatTime } from '..' -import { PluginsData } from '@/models/ThemeConfig.class' +import { Locales, PluginsData } from '@/models/ThemeConfig.class' type WalinePlugin = PluginsData['waline'] interface WalineConfig extends WalinePlugin { - lang: string + lang: Locales } interface WalineComment { @@ -92,7 +92,7 @@ export const walineCommentViewInit = (serverURL: string, path: string) => { export class WalineComments { configs: Partial = { serverURL: '', - lang: '' + lang: 'en' } constructor({ serverURL, lang }: Partial) { diff --git a/tsconfig.json b/tsconfig.json index 40c562df..35f53dd4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,13 @@ "resolveJsonModule": true, "sourceMap": true, "baseUrl": ".", - "types": ["vite/client", "jest", "node", "vite-plugin-svg-icons/client"], + "types": [ + "vite/client", + "jest", + "node", + "vite-plugin-svg-icons/client", + "vite-plugin-pages/client" + ], "paths": { "@/*": ["src/*"] }, diff --git a/vite-env.d.ts b/vite-env.d.ts new file mode 100644 index 00000000..cff98b07 --- /dev/null +++ b/vite-env.d.ts @@ -0,0 +1,2 @@ +// vite-env.d.ts +/// diff --git a/vite.config.js b/vite.config.js index 8affcaf6..3b94f4b3 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,15 +1,21 @@ -import { defineConfig, loadEnv } from 'vite'; +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' import { createHtmlPlugin } from 'vite-plugin-html-transformer' - +import Pages from 'vite-plugin-pages' import path from 'path' // https://vitejs.dev/config/ -export default (({mode}) => { - process.env = {...process.env, ...loadEnv(mode, process.cwd())}; - const filenamePath = process.env.VITE_MODE === 'production' ? '../layout/index.ejs' : 'index.html'; - const templatePath = process.env.VITE_MODE === 'production' ? 'templates/index_prod.html' : 'templates/index.html'; +export default ({ mode }) => { + process.env = { ...process.env, ...loadEnv(mode, process.cwd()) } + const filenamePath = + process.env.VITE_MODE === 'production' + ? '../layout/index.ejs' + : 'index.html' + const templatePath = + process.env.VITE_MODE === 'production' + ? 'templates/index_prod.html' + : 'templates/index.html' return defineConfig({ build: { @@ -17,18 +23,18 @@ export default (({mode}) => { assetsDir: 'static', rollupOptions: { output: { - assetFileNames: (assetInfo) => { - let extType = assetInfo.name.split('.').at(1); + assetFileNames: assetInfo => { + let extType = assetInfo.name.split('.').at(1) if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) { - extType = 'img'; + extType = 'img' } - return `static/${extType}/[name]-[hash][extname]`; + return `static/${extType}/[hash][extname]` }, - chunkFileNames: 'static/js/[name]-[hash].js', - entryFileNames: 'static/js/[name]-[hash].js', + chunkFileNames: 'static/js/[hash].js', + entryFileNames: 'static/js/[hash].js' }, plugins: [] - }, + } }, plugins: [ createSvgIconsPlugin({ @@ -47,15 +53,16 @@ export default (({mode}) => { * custom dom id * @default: __svg__icons__dom__ */ - customDomId: '__svg__icons__dom__', + customDomId: '__svg__icons__dom__' }), createHtmlPlugin({ minify: true, entry: '/src/main.ts', filename: filenamePath, - template: templatePath, + template: templatePath }), vue(), + Pages({}) ], resolve: { alias: { @@ -68,14 +75,14 @@ export default (({mode}) => { '/api': { target: 'http://localhost:4000/api', changeOrigin: true, - rewrite: (path) => path.replace(/^\/api/, ''), + rewrite: path => path.replace(/^\/api/, '') }, '/assets': { target: 'http://localhost:4000/assets', changeOrigin: true, - rewrite: (path) => path.replace(/^\/assets/, ''), + rewrite: path => path.replace(/^\/assets/, '') } } } }) -}) +} diff --git a/vue.config.js b/vue.config.js index d78bdcb6..d714a538 100644 --- a/vue.config.js +++ b/vue.config.js @@ -80,14 +80,14 @@ module.exports = { config // https://webpack.js.org/configuration/devtool/#development - .when(process.env.NODE_ENV === 'development', (config) => + .when(process.env.NODE_ENV === 'development', config => config.devtool('cheap-source-map') ) - config.when(process.env.NODE_ENV !== 'development', (config) => { + config.when(process.env.NODE_ENV !== 'development', config => { // htmlWebpackPlugin // https://github.com/jantimon/html-webpack-plugin - config.plugin('html').tap((args) => { + config.plugin('html').tap(args => { args[0].filename = path.resolve(__dirname, './layout/index.ejs') args[0].template = path.resolve(__dirname, './public/index_prod.html') return args @@ -127,7 +127,7 @@ module.exports = { // CopyWebpackPlugin Configs // https://github.com/webpack-contrib/copy-webpack-plugin - config.plugin('copy').tap((args) => { + config.plugin('copy').tap(args => { args[0][0].to = path.resolve(__dirname, './source') args[0][0].ignore = ['.*', '*.html'] return args