diff --git a/vite.config.ts b/vite.config.ts index d7ac9fd1..0f0c6169 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -116,6 +116,7 @@ export default defineConfig({ '@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)), + 'webcrypto-liner-shim': !process.env.VERCEL ? 'webcrypto-liner-shim' : fileURLToPath(new URL('./src/_empty.ts', import.meta.url)), }, }, define: { @@ -130,31 +131,34 @@ export default defineConfig({ minify: !process.env.VERCEL, reportCompressedSize: !process.env.VERCEL, // cssMinify: false, - modulePreload: false, + // modulePreload: false, rollupOptions: { - external: ['regex', './out/isolated_vm', 'isolated-vm', 'onnxruntime-node'], + external: ['regex', './out/isolated_vm', 'isolated-vm', 'onnxruntime-node', + ...(process.env.VERCEL ? ['webcrypto-liner-shim'] : []) + ], output: { format: 'es', - manualChunks: (id) => { - // if (id.includes('monaco-editor')) return 'monaco-editor'; - if (id.includes('tesseract.js')) return 'tesseract.js'; - if (id.includes('pdfjs')) return 'pdfjs'; - if (id.includes('unicode')) return 'unicode'; - // if (id.includes('transformers')) return 'transformers'; - // if (id.includes("node_modules")) { - // return "vendor"; - // } - }, - sourcemapIgnoreList: (relativeSourcePath) => { - const normalizedPath = path.normalize(relativeSourcePath); - return normalizedPath.includes("node_modules"); - }, + // manualChunks: (id) => { + // // if (id.includes('monaco-editor')) return 'monaco-editor'; + // if (id.includes('tesseract.js')) return 'tesseract.js'; + // if (id.includes('pdfjs')) return 'pdfjs'; + // if (id.includes('unicode')) return 'unicode'; + // // if (id.includes('transformers')) return 'transformers'; + // // if (id.includes("node_modules")) { + // // return "vendor"; + // // } + // }, + // sourcemapIgnoreList: (relativeSourcePath) => { + // const normalizedPath = path.normalize(relativeSourcePath); + // return normalizedPath.includes("node_modules"); + // }, }, cache: false, }, }, optimizeDeps: { - include: ['isolated-vm', 'pdfjs-dist', 'onnxruntime-node'], // optionally specify dependency name + include: ['isolated-vm', 'pdfjs-dist', 'onnxruntime-node', + ...(process.env.VERCEL ? ['webcrypto-liner-shim'] : [])], // optionally specify dependency name esbuildOptions: { supported: { 'top-level-await': true,