-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.ts
More file actions
57 lines (49 loc) · 1.5 KB
/
Copy pathindex.ts
File metadata and controls
57 lines (49 loc) · 1.5 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
import type { Plugin } from 'vite';
import { bundleVat } from './bundle-vat.ts';
export { bundleVat, removeDynamicImportsPlugin } from './bundle-vat.ts';
export type { VatBundle } from './bundle-vat.ts';
export { replaceNodeEnvPlugin } from './replace-node-env-plugin.ts';
export type { ReplaceNodeEnvPluginOptions } from './replace-node-env-plugin.ts';
type VatEntry = {
/** Absolute path to the vat source file */
source: string;
/** Output path relative to build outDir (e.g., 'echo/echo-caplet.bundle') */
output: string;
};
type BundleVatsOptions = {
vats: VatEntry[];
};
/**
* Vite plugin that bundles vat source files as part of the build pipeline.
*
* Registers vat sources for watch mode and emits bundled assets during
* `generateBundle`.
*
* @param options - Plugin options specifying which vats to bundle.
* @returns A Vite plugin.
*/
export function bundleVats(options: BundleVatsOptions): Plugin {
return {
name: 'ocap-kernel:bundle-vats',
buildStart() {
for (const vat of options.vats) {
this.addWatchFile(vat.source);
}
},
async generateBundle() {
const results = await Promise.all(
options.vats.map(async (vat) => {
const bundle = await bundleVat(vat.source);
return { fileName: vat.output, bundle };
}),
);
for (const { fileName, bundle } of results) {
this.emitFile({
type: 'asset',
fileName,
source: JSON.stringify(bundle),
});
}
},
};
}