-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathvite.config.kernel.js
More file actions
78 lines (74 loc) · 2.01 KB
/
vite.config.kernel.js
File metadata and controls
78 lines (74 loc) · 2.01 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
// vite.config.kernel.js (ESM)
import { defineConfig } from 'vite';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const wasmPath = resolve(__dirname, 'manifold-plus/dist/manifold.wasm');
const wasmBase64 = fs.readFileSync(wasmPath, 'base64');
function patchManifoldNodeImports() {
return {
name: 'patch-manifold-node-imports',
transform(code, id) {
const normalizedId = id.replaceAll('\\', '/');
const isLocalModule = normalizedId.includes('/manifold-plus/dist/manifold.js');
if (!isLocalModule) return null;
return {
code: code
.replace('await import("module")', 'await import("node:module")')
.replaceAll('require("fs")', 'require("node:fs")')
.replaceAll('require("path")', 'require("node:path")')
.replaceAll('require("url")', 'require("node:url")'),
map: null,
};
},
};
}
export default defineConfig({
plugins: [patchManifoldNodeImports()],
resolve: {
conditions: ['browser', 'import', 'module', 'default'],
alias: {
'#textToFace/fontUrlLoaders': resolve(__dirname, 'src/features/textToFace/fontUrlLoaders.kernel.js'),
},
},
esbuild: {
keepNames: true,
supported: {
'class-static-blocks': false,
},
},
build: {
lib: {
entry: resolve(__dirname, 'src/index.js'),
formats: ['es'],
fileName: () => 'brep-kernel.js',
},
outDir: 'dist-kernel',
emptyOutDir: true,
target: 'esnext',
minify: 'esbuild',
cssCodeSplit: false,
rollupOptions: {
external: [
'module',
'node:module',
'fs',
'node:fs',
'fs/promises',
'node:fs/promises',
'path',
'node:path',
'url',
'node:url',
],
output: {
inlineDynamicImports: true,
manualChunks: undefined,
},
},
},
define: {
__MANIFOLD_WASM_BASE64__: JSON.stringify(wasmBase64),
},
});