@@ -18,17 +18,19 @@ import Icons from 'unplugin-icons/vite';
1818import IconsResolver from 'unplugin-icons/resolver' ;
1919import VueI18n from '@intlify/unplugin-vue-i18n/vite' ;
2020
21+ import fs from 'node:fs' ;
22+ import fg from 'fast-glob' ;
23+ import Sitemap from 'vite-plugin-sitemap' ;
24+
2125import { visualizer } from 'rollup-plugin-visualizer' ;
2226
2327const baseUrl = process . env . BASE_URL || '/' ;
28+ const hostname = process . env . HOSTNAME ;
2429
2530// Locales are code-split: only en is bundled eagerly, the rest become lazy chunks fetched on
2631// first use (see src/plugins/i18n.plugin.ts). VITE_AVAILABLE_LOCALES filters the locales
2732// offered at runtime instead of trimming the build.
28- const includeLocales = [
29- resolve ( __dirname , 'src/tools/*/locales/**' ) ,
30- resolve ( __dirname , 'locales/**' ) ,
31- ] ;
33+ const includeLocales = [ resolve ( __dirname , 'src/tools/*/locales/**' ) , resolve ( __dirname , 'locales/**' ) ] ;
3234
3335// https://vitejs.dev/config/
3436export default defineConfig ( {
@@ -67,15 +69,16 @@ export default defineConfig({
6769 // tool chunk and WASM binary (~160 MB) on first visit; hashed assets are
6870 // cached on demand as tools are opened. Set VITE_PWA_FULL_PRECACHE=true to
6971 // restore full offline precaching of everything.
70- globPatterns : ( process . env . VITE_PWA_FULL_PRECACHE === 'true' && ! process . env . VITE_VERCEL_DEPLOY )
71- ? [ '**\/*.{js,wasm,css,html}' ]
72- : [ '**\/*.{css,html}' ] ,
72+ globPatterns :
73+ process . env . VITE_PWA_FULL_PRECACHE === 'true' && ! process . env . VITE_VERCEL_DEPLOY
74+ ? [ '**\/*.{js,wasm,css,html}' ]
75+ : [ '**\/*.{css,html}' ] ,
7376 maximumFileSizeToCacheInBytes : 25 * 1024 ** 2 ,
7477 navigateFallback : `${ baseUrl } index.html` ,
7578 runtimeCaching : [
7679 {
77- urlPattern : ( { sameOrigin, request } ) => sameOrigin
78- && ( request . destination === 'script' || request . destination === 'worker' ) ,
80+ urlPattern : ( { sameOrigin, request } ) =>
81+ sameOrigin && ( request . destination === 'script' || request . destination === 'worker' ) ,
7982 handler : 'CacheFirst' ,
8083 options : {
8184 cacheName : 'app-chunks' ,
@@ -142,19 +145,44 @@ export default defineConfig({
142145 nodePolyfills ( ) ,
143146 wasm ( ) ,
144147 visualizer ( ) ,
148+ hostname
149+ ? Sitemap ( {
150+ hostname,
151+ generateRobotsTxt : true ,
152+ robots : [ { userAgent : '*' , allow : '/' } ] ,
153+ dynamicRoutes : ( ( ) => {
154+ const paths = [ '/' , '/about' ] ;
155+ fg . sync ( 'src/tools/*/index.ts' ) . forEach ( ( file ) => {
156+ const content = fs . readFileSync ( file , 'utf-8' ) ;
157+ const pathMatch = content . match ( / p a t h : \s * [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / ) ;
158+ if ( pathMatch ) {
159+ paths . push ( pathMatch [ 1 ] ) ;
160+ }
161+ const redirectMatch = content . match ( / r e d i r e c t F r o m : \s * \[ ( [ ^ \] ] + ) \] / ) ;
162+ if ( redirectMatch ?. [ 1 ] ) {
163+ const redirectPaths = redirectMatch [ 1 ] . match ( / [ ' " ` ] ( [ ^ ' " ` ] + ) [ ' " ` ] / g) ;
164+ redirectPaths ?. forEach ( ( p ) => paths . push ( p . replace ( / [ ' " ` ] / g, '' ) ) ) ;
165+ }
166+ } ) ;
167+ return paths ;
168+ } ) ( ) ,
169+ } )
170+ : undefined ,
145171 ] ,
146172 base : baseUrl ,
147173 resolve : {
148174 alias : {
149175 '@' : fileURLToPath ( new URL ( './src' , import . meta. url ) ) ,
150176 'node:fs/promises' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
151177 'node:fs' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
152- 'fs' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
178+ fs : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
153179 '@babel/core' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
154180 'isolated-vm' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
155181 'onnxruntime-node' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
156182 'unpdf/pdfjs' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
157- 'webcrypto-liner-shim' : ! process . env . VERCEL ? 'webcrypto-liner-shim' : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
183+ 'webcrypto-liner-shim' : ! process . env . VERCEL
184+ ? 'webcrypto-liner-shim'
185+ : fileURLToPath ( new URL ( './src/_empty.ts' , import . meta. url ) ) ,
158186 } ,
159187 } ,
160188 define : {
@@ -197,7 +225,16 @@ export default defineConfig({
197225 } ,
198226 } ,
199227 optimizeDeps : {
200- include : [ 'isolated-vm' , '@lezer/highlight' , 'pdfjs-dist' , 'onnxruntime-node' , 'onnxruntime-web' , 'unpdf' , 'unpdf/pdfjs' , ...( process . env . VERCEL ? [ 'webcrypto-liner-shim' ] : [ ] ) ] , // optionally specify dependency name
228+ include : [
229+ 'isolated-vm' ,
230+ '@lezer/highlight' ,
231+ 'pdfjs-dist' ,
232+ 'onnxruntime-node' ,
233+ 'onnxruntime-web' ,
234+ 'unpdf' ,
235+ 'unpdf/pdfjs' ,
236+ ...( process . env . VERCEL ? [ 'webcrypto-liner-shim' ] : [ ] ) ,
237+ ] , // optionally specify dependency name
201238 } ,
202239 // server: {
203240 // headers: {
0 commit comments