-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
150 lines (148 loc) · 4.83 KB
/
vite.config.ts
File metadata and controls
150 lines (148 loc) · 4.83 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import path from 'path'
// All shared packages that need to be resolved from mobile/node_modules
const sharedPackages = [
// React ecosystem
'react',
'react-dom',
'react-router-dom',
'react-dropzone',
// i18n
'react-i18next',
'i18next',
'i18next-browser-languagedetector',
// State management
'zustand',
// HTTP
'axios',
// UI
'lucide-react',
'class-variance-authority',
'clsx',
'tailwind-merge',
'@tanstack/react-virtual',
// Radix UI
'@radix-ui/react-alert-dialog',
'@radix-ui/react-checkbox',
'@radix-ui/react-dialog',
'@radix-ui/react-dropdown-menu',
'@radix-ui/react-hover-card',
'@radix-ui/react-label',
'@radix-ui/react-progress',
'@radix-ui/react-scroll-area',
'@radix-ui/react-select',
'@radix-ui/react-separator',
'@radix-ui/react-slider',
'@radix-ui/react-slot',
'@radix-ui/react-switch',
'@radix-ui/react-tabs',
'@radix-ui/react-toast',
'@radix-ui/react-tooltip',
// AI/ML
'@huggingface/transformers',
'@imgly/background-removal',
'upscaler',
'@upscalerjs/default-model',
'@upscalerjs/esrgan-medium',
'@upscalerjs/esrgan-slim',
'@upscalerjs/esrgan-thick',
// Video encoding
'webm-muxer',
'mp4-muxer',
// ONNX Runtime
'onnxruntime-web',
// TensorFlow
'@tensorflow/tfjs-core',
'@tensorflow/tfjs-backend-wasm',
// Capacitor plugins (used by platform service)
'@capacitor/core',
'@capacitor/preferences',
'@capacitor/filesystem',
'@capacitor/browser',
'@capacitor/share',
'@capacitor/app',
'@capacitor/camera',
'@capacitor/status-bar',
'@capacitor/splash-screen',
'@capacitor/keyboard',
]
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
// Copy ESRGAN model files to dist/models/
// Only bundling slim models to keep APK size reasonable (~4MB)
// Models are loaded from relative path 'models/x{scale}/model.json'
viteStaticCopy({
targets: [
{
src: 'node_modules/@upscalerjs/esrgan-slim/models/*',
dest: 'models'
}
]
})
],
resolve: {
alias: {
// Mobile-specific overrides (must come before @/)
'@/hooks/useSegmentAnythingWorker': path.resolve(__dirname, './src/hooks/useSegmentAnythingWorker'),
'@/hooks/useUpscalerWorker': path.resolve(__dirname, './src/hooks/useUpscalerWorker'),
'@/hooks/useBackgroundRemoverWorker': path.resolve(__dirname, './src/hooks/useBackgroundRemoverWorker'),
'@/hooks/useImageEraserWorker': path.resolve(__dirname, './src/hooks/useImageEraserWorker'),
'@/components/playground/DynamicForm': path.resolve(__dirname, './src/components/playground/DynamicForm'),
'@/components/playground/FileUpload': path.resolve(__dirname, './src/components/playground/FileUpload'),
'@/components/playground/FormField': path.resolve(__dirname, './src/components/playground/FormField'),
'@/components/playground/PromptOptimizer': path.resolve(__dirname, './src/components/playground/PromptOptimizer'),
'@/components/playground/SizeSelector': path.resolve(__dirname, './src/components/playground/SizeSelector'),
'@/pages/SettingsPage': path.resolve(__dirname, './src/pages/SettingsPage'),
// Share code from the main src directory
'@': path.resolve(__dirname, '../src'),
// Mobile-specific code
'@mobile': path.resolve(__dirname, './src')
},
// Dedupe these packages to ensure they're resolved from mobile/node_modules
dedupe: sharedPackages
},
build: {
outDir: 'dist',
sourcemap: true,
commonjsOptions: {
include: [/node_modules/],
transformMixedEsModules: true
},
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
'ui-vendor': ['@radix-ui/react-dialog', '@radix-ui/react-select', '@radix-ui/react-slider'],
'ai-vendor': ['upscaler', '@imgly/background-removal', 'onnxruntime-web']
}
}
}
},
worker: {
format: 'es'
},
optimizeDeps: {
include: sharedPackages.filter(p => !['@huggingface/transformers', 'onnxruntime-web'].includes(p)),
exclude: ['@huggingface/transformers', 'onnxruntime-web']
},
// Ensure WASM files are properly served
assetsInclude: ['**/*.wasm'],
server: {
port: 5173,
host: true, // Allow access from network for mobile device testing
headers: {
// Required for SharedArrayBuffer support (ONNX Runtime multi-threading)
// Using 'credentialless' instead of 'require-corp' to allow loading external images
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'credentialless'
},
fs: {
// Allow serving files from parent directory (for shared src)
allow: ['..']
}
}
})