diff --git a/.github/workflows/sharevb-vercel-prod.yml b/.github/workflows/sharevb-vercel-prod.yml index e0f83665..0b547358 100644 --- a/.github/workflows/sharevb-vercel-prod.yml +++ b/.github/workflows/sharevb-vercel-prod.yml @@ -4,6 +4,7 @@ env: VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} VITE_VERCEL_ENV: production VITE_VERCEL_DEPLOY: true + HOSTNAME: https://sharevb-it-tools.vercel.app/ on: push: branches: @@ -20,4 +21,4 @@ jobs: - name: Build Project Artifacts run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} - name: Deploy Project Artifacts to Vercel - run: vercel deploy --prebuilt --archive=tgz --prod --token=${{ secrets.VERCEL_TOKEN }} \ No newline at end of file + run: vercel deploy --prebuilt --archive=tgz --prod --token=${{ secrets.VERCEL_TOKEN }} diff --git a/package.json b/package.json index a053dd37..e6ee11e6 100644 --- a/package.json +++ b/package.json @@ -379,6 +379,7 @@ "utf8": "^3.0.0", "uuid": "^14.0.1", "vanilla-jsoneditor": "^3.12.0", + "vite-plugin-sitemap": "^0.8.2", "vue": "^3.5.39", "vue-color-wheel": "^0.1.1", "vue-i18n": "^11.4.6", @@ -457,6 +458,7 @@ "commander": "^15.0.0", "consola": "^3.4.2", "dotenv": "^17.4.2", + "fast-glob": "^3.3.3", "hygen": "^6.2.11", "jsdom": "^29.1.1", "less": "^4.6.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7abe4f3b..6adf802a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1026,6 +1026,9 @@ importers: vanilla-jsoneditor: specifier: ^3.12.0 version: 3.12.0(@typescript-eslint/types@8.62.1) + vite-plugin-sitemap: + specifier: ^0.8.2 + version: 0.8.2 vue: specifier: ^3.5.39 version: 3.5.39(typescript@6.0.3) @@ -1255,6 +1258,9 @@ importers: dotenv: specifier: ^17.4.2 version: 17.4.2 + fast-glob: + specifier: ^3.3.3 + version: 3.3.3 hygen: specifier: ^6.2.11 version: 6.2.11 @@ -11012,6 +11018,9 @@ packages: '@vite-pwa/assets-generator': optional: true + vite-plugin-sitemap@0.8.2: + resolution: {integrity: sha512-bqIw6NVOXg6je81lzX8Lm0vjf8/QSAp8di8fYQzZ3ZdVicOm8+6idBGALJiy1R1FiXNIK8rgORO6HBqXyHW+iQ==} + vite-plugin-wasm@3.6.0: resolution: {integrity: sha512-mL/QPziiIA4RAA6DkaZZzOstdwbW5jO4Vz7Zenj0wieKWBlNvIvX5L5ljum9lcUX0ShNfBgCNLKTjNkRVVqcsw==} peerDependencies: @@ -22248,6 +22257,8 @@ snapshots: transitivePeerDependencies: - supports-color + vite-plugin-sitemap@0.8.2: {} + vite-plugin-wasm@3.6.0(vite@8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0)): dependencies: vite: 8.1.3(@types/node@24.13.3)(jiti@2.7.0)(less@4.6.7)(terser@5.48.0)(yaml@2.9.0) diff --git a/vercel.json b/vercel.json index ede75882..e9a0d8db 100644 --- a/vercel.json +++ b/vercel.json @@ -3,7 +3,20 @@ "git": { "deploymentEnabled": false }, - "rewrites": [{ "source": "/:path*", "destination": "/index.html" }], + "rewrites": [ + { + "source": "/robots.txt", + "destination": "/robots.txt" + }, + { + "source": "/sitemap.xml", + "destination": "/sitemap.xml" + }, + { + "source": "/:path*", + "destination": "/index.html" + } + ], "headers": [ { "source": "/index.html", @@ -24,4 +37,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/vite.config.ts b/vite.config.ts index da4365ce..5bb3dc16 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -18,17 +18,19 @@ import Icons from 'unplugin-icons/vite'; import IconsResolver from 'unplugin-icons/resolver'; import VueI18n from '@intlify/unplugin-vue-i18n/vite'; +import fs from 'node:fs'; +import fg from 'fast-glob'; +import Sitemap from 'vite-plugin-sitemap'; + import { visualizer } from 'rollup-plugin-visualizer'; const baseUrl = process.env.BASE_URL || '/'; +const hostname = process.env.HOSTNAME; // Locales are code-split: only en is bundled eagerly, the rest become lazy chunks fetched on // first use (see src/plugins/i18n.plugin.ts). VITE_AVAILABLE_LOCALES filters the locales // offered at runtime instead of trimming the build. -const includeLocales = [ - resolve(__dirname, 'src/tools/*/locales/**'), - resolve(__dirname, 'locales/**'), -]; +const includeLocales = [resolve(__dirname, 'src/tools/*/locales/**'), resolve(__dirname, 'locales/**')]; // https://vitejs.dev/config/ export default defineConfig({ @@ -67,15 +69,16 @@ export default defineConfig({ // tool chunk and WASM binary (~160 MB) on first visit; hashed assets are // cached on demand as tools are opened. Set VITE_PWA_FULL_PRECACHE=true to // restore full offline precaching of everything. - globPatterns: (process.env.VITE_PWA_FULL_PRECACHE === 'true' && !process.env.VITE_VERCEL_DEPLOY) - ? ['**\/*.{js,wasm,css,html}'] - : ['**\/*.{css,html}'], + globPatterns: + process.env.VITE_PWA_FULL_PRECACHE === 'true' && !process.env.VITE_VERCEL_DEPLOY + ? ['**\/*.{js,wasm,css,html}'] + : ['**\/*.{css,html}'], maximumFileSizeToCacheInBytes: 25 * 1024 ** 2, navigateFallback: `${baseUrl}index.html`, runtimeCaching: [ { - urlPattern: ({ sameOrigin, request }) => sameOrigin - && (request.destination === 'script' || request.destination === 'worker'), + urlPattern: ({ sameOrigin, request }) => + sameOrigin && (request.destination === 'script' || request.destination === 'worker'), handler: 'CacheFirst', options: { cacheName: 'app-chunks', @@ -142,6 +145,29 @@ export default defineConfig({ nodePolyfills(), wasm(), visualizer(), + hostname + ? Sitemap({ + hostname, + generateRobotsTxt: true, + robots: [{ userAgent: '*', allow: '/' }], + dynamicRoutes: (() => { + const paths = ['/', '/about']; + fg.sync('src/tools/*/index.ts').forEach((file) => { + const content = fs.readFileSync(file, 'utf-8'); + const pathMatch = content.match(/path:\s*['"`]([^'"`]+)['"`]/); + if (pathMatch) { + paths.push(pathMatch[1]); + } + const redirectMatch = content.match(/redirectFrom:\s*\[([^\]]+)\]/); + if (redirectMatch?.[1]) { + const redirectPaths = redirectMatch[1].match(/['"`]([^'"`]+)['"`]/g); + redirectPaths?.forEach((p) => paths.push(p.replace(/['"`]/g, ''))); + } + }); + return paths; + })(), + }) + : undefined, ], base: baseUrl, resolve: { @@ -149,12 +175,14 @@ export default defineConfig({ '@': fileURLToPath(new URL('./src', import.meta.url)), 'node:fs/promises': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'node:fs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), - 'fs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), + fs: fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), '@babel/core': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'isolated-vm': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'onnxruntime-node': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), 'unpdf/pdfjs': fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), - 'webcrypto-liner-shim': !process.env.VERCEL ? 'webcrypto-liner-shim' : fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), + 'webcrypto-liner-shim': !process.env.VERCEL + ? 'webcrypto-liner-shim' + : fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), }, }, define: { @@ -197,7 +225,16 @@ export default defineConfig({ }, }, optimizeDeps: { - include: ['isolated-vm', '@lezer/highlight', 'pdfjs-dist', 'onnxruntime-node', 'onnxruntime-web', 'unpdf', 'unpdf/pdfjs', ...(process.env.VERCEL ? ['webcrypto-liner-shim'] : [])], // optionally specify dependency name + include: [ + 'isolated-vm', + '@lezer/highlight', + 'pdfjs-dist', + 'onnxruntime-node', + 'onnxruntime-web', + 'unpdf', + 'unpdf/pdfjs', + ...(process.env.VERCEL ? ['webcrypto-liner-shim'] : []), + ], // optionally specify dependency name }, // server: { // headers: {