|
1 | | -import { defineConfig } from 'vite'; |
| 1 | +import { defineConfig, type Plugin } from 'vite'; |
2 | 2 | import { resolve } from 'path'; |
3 | 3 | import { fileURLToPath } from 'url'; |
| 4 | +import { rmSync } from 'fs'; |
4 | 5 | import dts from 'vite-plugin-dts'; |
5 | 6 |
|
6 | 7 | const __dirname = fileURLToPath(new URL('.', import.meta.url)); |
7 | 8 |
|
| 9 | +// Plugin to clean up extra assets generated by @sqlite.org/sqlite-wasm |
| 10 | +function cleanupAssets(): Plugin { |
| 11 | + return { |
| 12 | + name: 'cleanup-assets', |
| 13 | + closeBundle() { |
| 14 | + // Remove the assets folder containing duplicate SQLite workers |
| 15 | + // Everything is inlined via ?worker&inline, so these aren't needed |
| 16 | + try { |
| 17 | + rmSync(resolve(__dirname, 'dist/assets'), { recursive: true, force: true }); |
| 18 | + } catch { |
| 19 | + // Ignore if folder doesn't exist |
| 20 | + } |
| 21 | + }, |
| 22 | + }; |
| 23 | +} |
| 24 | + |
8 | 25 | export default defineConfig({ |
9 | 26 | root: '.', // Root directory for dev server |
10 | | - plugins: [dts({ rollupTypes: true })], |
| 27 | + plugins: [dts({ rollupTypes: true }), cleanupAssets()], |
11 | 28 | build: { |
12 | 29 | lib: { |
13 | | - entry: { |
14 | | - index: resolve(__dirname, 'src/index.ts'), |
15 | | - worker: resolve(__dirname, 'src/worker/sqliteWorker.ts'), |
16 | | - }, |
| 30 | + // Only export the main entry - worker is inlined via ?worker&inline |
| 31 | + entry: resolve(__dirname, 'src/index.ts'), |
17 | 32 | formats: ['es'], |
18 | | - fileName: (format, entryName) => `${entryName}.js`, |
| 33 | + fileName: () => 'index.js', |
19 | 34 | }, |
20 | 35 | rollupOptions: { |
21 | | - // Don't mark sqlite-wasm as external - bundle it into the worker |
22 | | - // so the inlined worker is self-contained and works offline |
23 | 36 | output: { |
24 | | - preserveModules: false, |
| 37 | + // Prevent code splitting - everything in one file |
| 38 | + manualChunks: undefined, |
| 39 | + inlineDynamicImports: true, |
25 | 40 | }, |
26 | 41 | }, |
27 | 42 | target: 'es2022', |
28 | 43 | outDir: 'dist', |
29 | 44 | emptyOutDir: true, |
30 | | - sourcemap: true, |
| 45 | + // Disable source maps for smaller production builds |
| 46 | + sourcemap: false, |
| 47 | + // Minify for smaller output |
| 48 | + minify: 'esbuild', |
31 | 49 | }, |
32 | 50 | server: { |
33 | 51 | open: '/examples/basic.html', // Auto-open examples on dev server start |
|
0 commit comments