Skip to content

Commit 14ac202

Browse files
committed
✨ feat: Configure Vite to produce a single, minified library output
1 parent 619a6eb commit 14ac202

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@haroonwaves/sqlite-wasm-easy",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "A simple, zero-config wrapper around @sqlite.org/sqlite-wasm",
55
"type": "module",
66
"main": "./dist/index.js",

vite.config.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
import { defineConfig } from 'vite';
1+
import { defineConfig, type Plugin } from 'vite';
22
import { resolve } from 'path';
33
import { fileURLToPath } from 'url';
4+
import { rmSync } from 'fs';
45
import dts from 'vite-plugin-dts';
56

67
const __dirname = fileURLToPath(new URL('.', import.meta.url));
78

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+
825
export default defineConfig({
926
root: '.', // Root directory for dev server
10-
plugins: [dts({ rollupTypes: true })],
27+
plugins: [dts({ rollupTypes: true }), cleanupAssets()],
1128
build: {
1229
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'),
1732
formats: ['es'],
18-
fileName: (format, entryName) => `${entryName}.js`,
33+
fileName: () => 'index.js',
1934
},
2035
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
2336
output: {
24-
preserveModules: false,
37+
// Prevent code splitting - everything in one file
38+
manualChunks: undefined,
39+
inlineDynamicImports: true,
2540
},
2641
},
2742
target: 'es2022',
2843
outDir: 'dist',
2944
emptyOutDir: true,
30-
sourcemap: true,
45+
// Disable source maps for smaller production builds
46+
sourcemap: false,
47+
// Minify for smaller output
48+
minify: 'esbuild',
3149
},
3250
server: {
3351
open: '/examples/basic.html', // Auto-open examples on dev server start

0 commit comments

Comments
 (0)