-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
121 lines (118 loc) · 3.31 KB
/
vite.config.js
File metadata and controls
121 lines (118 loc) · 3.31 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { VitePWA } from "vite-plugin-pwa";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import fs from "fs";
import { viteStaticCopy } from "vite-plugin-static-copy";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
VitePWA({
registerType: "prompt",
injectRegister: false,
pwaAssets: {
disabled: true,
config: false,
},
manifest: {
name: "RoadXpert",
short_name: "RoadXpert",
description: "Your eyes on the road",
theme_color: "#ffffff",
},
workbox: {
globPatterns: ["**/*.{js,css,html,svg,png,ico,wasm,onnx,json,bin}"],
cleanupOutdatedCaches: true,
maximumFileSizeToCacheInBytes: 50 * 1024 * 1024, // Increased to 50MB for model files
clientsClaim: true,
// Exclude model files from precaching to avoid cache issues during development
dontCacheBustURLsMatching: /\.(bin|json)$/,
// Allow large model files
runtimeCaching: [
{
urlPattern: /.*_web_model\/.*/,
handler: "CacheFirst",
options: {
cacheName: "ml-models",
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 30, // 30 days
},
},
},
],
},
devOptions: {
enabled: false,
navigateFallback: "index.html",
suppressWarnings: true,
type: "module",
},
}),
viteStaticCopy({
targets: [
{
src: "node_modules/onnxruntime-web/dist/*.wasm",
dest: "static/js",
},
{
src: "node_modules/@tensorflow/tfjs-backend-wasm/dist/*.wasm",
dest: ".", // Copy to root directory for easier access
},
],
}),
],
optimizeDeps: {
exclude: ["onnxruntime-web"],
},
server: {
// host: true, // מאפשר גישה מה־LAN
// https: {
// key: fs.readFileSync(
// path.resolve(__dirname, "cert/example.com+5-key.pem")
// ),
// cert: fs.readFileSync(path.resolve(__dirname, "cert/example.com+5.pem")),
// },
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
// Configure MIME types for WASM files
middlewareMode: false,
// Add WASM file serving configuration
fs: {
allow: ["."],
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
fs: path.resolve(__dirname, "./empty.js"),
path: path.resolve(__dirname, "./empty.js"),
crypto: path.resolve(__dirname, "./empty.js"),
},
},
assetsInclude: ["**/*.wasm", "**/*.onnx"],
// Configure WASM file serving with proper MIME type
define: {
global: "globalThis",
},
build: {
target: "esnext",
rollupOptions: {
external: [],
output: {
// Ensure WASM files are properly handled
assetFileNames: (assetInfo) => {
const info = assetInfo.name.split(".");
const extType = info[info.length - 1];
if (/\.(wasm)$/i.test(assetInfo.name)) {
return `assets/[name].[hash][extname]`;
}
return `assets/[name].[hash][extname]`;
},
},
},
},
});