-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathrollup.config.js
More file actions
128 lines (114 loc) · 3.2 KB
/
rollup.config.js
File metadata and controls
128 lines (114 loc) · 3.2 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import typescript from '@rollup/plugin-typescript';
import { wasm } from '@rollup/plugin-wasm';
import fs from 'fs';
import path from 'path';
// Create a plugin specifically for creating dummy WASM files and copying the original WASM file to dist root
const copyWasmFiles = () => {
return {
name: 'copy-wasm-files',
writeBundle: {
sequential: true, // Make sure this runs after all files are written
order: 'post', // Run this after all other writeBundle hooks
handler: (options) => {
// Extract the output directory from the output path
const outputDir = path.dirname(options.file || '');
// Ensure output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Create the dummy WASM file in the same directory as the output
const dummyWasmPath = path.join(
outputDir,
'flipt_engine_wasm_js_bg.wasm'
);
if (!fs.existsSync(dummyWasmPath)) {
console.log(`Creating dummy WASM file at ${dummyWasmPath}`);
// Create a minimal valid WASM file (8 bytes - magic number + version)
const dummyWasmContent = Buffer.from([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00
]);
fs.writeFileSync(dummyWasmPath, dummyWasmContent);
}
// Also ensure we have the original WASM file copied to dist root
const sourceWasmPath = path.resolve(
'src/wasm/flipt_engine_wasm_js_bg.wasm'
);
const targetWasmPath = path.resolve(
'dist/flipt_engine_wasm_js_bg.wasm'
);
if (fs.existsSync(sourceWasmPath) && !fs.existsSync(targetWasmPath)) {
console.log(`Copying original WASM file to ${targetWasmPath}`);
// Ensure dist directory exists
if (!fs.existsSync('dist')) {
fs.mkdirSync('dist', { recursive: true });
}
// Copy the file
fs.copyFileSync(sourceWasmPath, targetWasmPath);
}
}
}
};
};
const tsConfig = {
noEmit: true,
declaration: false,
declarationDir: null
};
const browserConfig = {
input: 'src/browser/index.ts',
output: [
{
file: 'dist/browser/index.mjs',
format: 'esm'
},
{
file: 'dist/browser/index.cjs',
format: 'cjs'
}
],
plugins: [
wasm({
targetEnv: 'auto-inline'
}),
typescript(tsConfig),
copyWasmFiles() // Add our dummy WASM creator
]
};
const nodeConfig = {
input: 'src/node/index.ts',
output: [
{
file: 'dist/node/index.mjs',
format: 'esm'
},
{
file: 'dist/node/index.cjs',
format: 'cjs'
}
],
plugins: [
wasm({
targetEnv: 'auto-inline'
}),
typescript(tsConfig),
copyWasmFiles() // Add our dummy WASM creator
],
external: ['node-fetch']
};
// Slim configuration that doesn't bundle the WASM file
const slimConfig = {
input: 'src/slim/index.ts',
output: [
{
file: 'dist/slim/index.mjs',
format: 'esm'
},
{
file: 'dist/slim/index.cjs',
format: 'cjs'
}
],
plugins: [typescript(tsConfig)],
external: ['node-fetch']
};
export default [browserConfig, nodeConfig, slimConfig];