-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathvite.lib.config.js
More file actions
91 lines (89 loc) · 2.19 KB
/
vite.lib.config.js
File metadata and controls
91 lines (89 loc) · 2.19 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import wasm from 'vite-plugin-wasm';
export default defineConfig({
plugins: [
wasm(),
{
name: 'browser-shims',
enforce: 'pre',
resolveId(source) {
if (source === 'node:zlib' || source === 'zlib') {
return resolve(__dirname, 'src/shims/zlib.ts');
}
if (source === 'brotli-wasm/pkg.web/brotli_wasm.js') {
return resolve(__dirname, 'node_modules/brotli-wasm/pkg.web/brotli_wasm.js');
}
if (source === 'brotli-wasm/pkg.web/brotli_wasm_bg.wasm?url') {
return {
id: resolve(__dirname, 'node_modules/brotli-wasm/pkg.web/brotli_wasm_bg.wasm') + '?url',
external: false,
};
}
return null;
},
},
],
define: {
'process.env': {},
global: 'globalThis',
},
resolve: {
alias: {
'node:zlib': resolve(__dirname, 'src/shims/zlib.ts'),
'zlib': resolve(__dirname, 'src/shims/zlib.ts'),
'buffer': 'buffer',
'process': 'process/browser',
},
},
worker: {
format: 'es',
plugins: () => [
wasm(),
],
rollupOptions: {
output: {
inlineDynamicImports: true,
},
},
},
build: {
lib: {
entry: {
index: resolve(__dirname, 'src/index.ts'),
'vite-plugin': resolve(__dirname, 'src/vite-plugin.ts'),
'next-plugin': resolve(__dirname, 'src/next-plugin.ts'),
},
name: 'JustNode',
formats: ['es', 'cjs'],
fileName: (format, entryName) => `${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`,
},
rollupOptions: {
external: [
'brotli-wasm',
'pako',
'comlink',
'just-bash',
'resolve.exports',
'brotli',
// Node.js built-ins for vite-plugin
'fs',
'path',
'url',
'vite',
],
output: {
globals: {
'brotli-wasm': 'brotliWasm',
'pako': 'pako',
'comlink': 'Comlink',
'just-bash': 'justBash',
'resolve.exports': 'resolveExports',
},
},
},
sourcemap: true,
minify: false,
},
assetsInclude: ['**/*.wasm'],
});