-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
70 lines (67 loc) · 1.82 KB
/
vite.config.ts
File metadata and controls
70 lines (67 loc) · 1.82 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
import { defineConfig, type Plugin } from 'vite';
import { resolve } from 'path';
import { fileURLToPath } from 'url';
import { rmSync } from 'fs';
import dts from 'vite-plugin-dts';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
// Plugin to clean up extra assets generated by @sqlite.org/sqlite-wasm
function cleanupAssets(): Plugin {
return {
name: 'cleanup-assets',
closeBundle() {
// Remove the assets folder containing duplicate SQLite workers
// Everything is inlined via ?worker&inline, so these aren't needed
try {
rmSync(resolve(__dirname, 'dist/assets'), { recursive: true, force: true });
} catch {
// Ignore if folder doesn't exist
}
},
};
}
export default defineConfig({
root: '.', // Root directory for dev server
plugins: [dts({ rollupTypes: true }), cleanupAssets()],
build: {
lib: {
// Only export the main entry - worker is inlined via ?worker&inline
entry: resolve(__dirname, 'src/index.ts'),
formats: ['es'],
fileName: () => 'index.js',
},
rollupOptions: {
output: {
// Prevent code splitting - everything in one file
manualChunks: undefined,
inlineDynamicImports: true,
},
},
target: 'es2022',
outDir: 'dist',
emptyOutDir: true,
// Disable source maps for smaller production builds
sourcemap: false,
// Minify for smaller output
minify: 'esbuild',
},
server: {
open: '/examples/basic.html', // Auto-open examples on dev server start
port: 5173,
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
},
optimizeDeps: {
exclude: ['@sqlite.org/sqlite-wasm'], // Don't pre-bundle SQLite WASM
},
worker: {
format: 'es',
rollupOptions: {
output: {
// Force everything into a single chunk for the worker
inlineDynamicImports: true,
},
},
},
});