Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
73 lines (70 loc) · 2.21 KB
/
Copy pathvite.config.ts
File metadata and controls
73 lines (70 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { copyFileSync, existsSync, mkdirSync } from 'fs'
import { resolve } from 'path'
// onnxruntime-web resolves these at runtime and would otherwise fetch them from
// a CDN on the first inference, which the local-first guarantee does not allow.
// Staging them in public/ makes them available at /ort/ in dev and dist/ort/ in
// a packaged build, which is what the embedding worker points wasmPaths at.
const ORT_RUNTIME_FILES = [
'ort-wasm-simd-threaded.mjs',
'ort-wasm-simd-threaded.wasm',
'ort-wasm-simd-threaded.jsep.mjs',
'ort-wasm-simd-threaded.jsep.wasm',
]
const stageOnnxRuntime = () => {
const source = resolve(__dirname, 'node_modules/onnxruntime-web/dist')
const target = resolve(__dirname, 'public/ort')
if (!existsSync(source)) {
console.warn('⚠️ onnxruntime-web not installed; visual search will not run')
return
}
mkdirSync(target, { recursive: true })
for (const file of ORT_RUNTIME_FILES) {
const from = resolve(source, file)
if (!existsSync(from)) continue
copyFileSync(from, resolve(target, file))
}
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
{
name: 'copy-assets',
buildStart() {
stageOnnxRuntime()
},
closeBundle() {
// Copy CHANGELOG.md to dist folder after build; Vite copies public assets.
try {
copyFileSync(
resolve(__dirname, 'CHANGELOG.md'),
resolve(__dirname, 'dist/CHANGELOG.md')
)
console.log('✅ CHANGELOG.md copied to dist/')
} catch (error) {
console.warn('⚠️ Failed to copy assets:', error)
}
}
}
],
base: './',
// Workers must be ES modules: onnxruntime-web (pulled in by the embedding
// worker) resolves its WASM backend through a dynamic import(), which the
// default iife worker format cannot express. Without this the packaged build
// fails while `npm run dev` keeps working.
worker: {
format: 'es',
},
server: {
host: true, // Expose server to the network
},
css: {
postcss: './postcss.config.cjs'
},
build: {
outDir: 'dist',
assetsDir: 'assets'
}
})