-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
65 lines (63 loc) · 2.23 KB
/
vite.config.ts
File metadata and controls
65 lines (63 loc) · 2.23 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
import { defineConfig } from 'vite';
import wasm from 'vite-plugin-wasm';
import { resolve } from 'path';
// Library build config — used by `npm run build:js` and `npm run release`.
// NOT used for the demo dev server (that uses vite.config.demo.ts).
//
// Outputs:
// dist/index.{mjs,cjs} — main Nodebox API
// dist/vite-plugin.{mjs,cjs} — optional Vite integration
// dist/middleware.{mjs,cjs} — optional Express middleware
// dist/*.d.ts — TypeScript declarations (via build:types)
export default defineConfig({
plugins: [wasm()],
build: {
lib: {
entry: {
index: resolve(__dirname, 'js/src/index.ts'),
'vite-plugin': resolve(__dirname, 'js/src/preview/vite-plugin.ts'),
middleware: resolve(__dirname, 'js/src/preview/middleware.ts'),
},
formats: ['es', 'cjs'],
fileName: (format, entryName) =>
`${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`,
},
rollupOptions: {
// Mark peer/runtime deps as external — not bundled into dist.
external: [
'nodebox-core',
/^nodebox-core\//,
'vite',
'esbuild-wasm',
/^node:/,
// Node.js built-in polyfill names (used as specifiers in require())
'fs', 'path', 'http', 'https', 'url', 'crypto', 'stream',
'os', 'net', 'tty', 'vm', 'util', 'assert', 'events',
'querystring', 'string_decoder', 'timers', 'zlib', 'buffer',
'child_process',
],
},
// Terser: maximum compression + strip all comments.
// Mangle _camelCase private properties to reduce readability.
minify: 'terser',
terserOptions: {
compress: {
passes: 2,
// Keep console.warn/error for runtime diagnostics; drop debug-only logs.
pure_funcs: ['console.debug'],
},
mangle: {
// Mangle properties starting with _lowercase (internal/private convention).
properties: { regex: /^_[a-z]/ },
},
format: {
// Strip all comments — no source hints in the published package.
comments: false,
},
},
// No source maps in the published package — prevents source reconstruction.
sourcemap: false,
outDir: 'dist',
emptyOutDir: true,
},
});