-
Notifications
You must be signed in to change notification settings - Fork 1
/
bundler.ts
32 lines (31 loc) · 935 Bytes
/
bundler.ts
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
import { rollup, httpResolve } from "./deps.ts";
import { denoLoader, svelte, compress } from "./plugins.ts";
export async function bundle(entryPath: string) {
const sourceGen = await rollup({
input: entryPath,
plugins: [
httpResolve({
resolveIdFallback(id: string, importer: any) {
if (importer == null) {
return;
}
if (id.startsWith(".")) {
return;
}
if (id.startsWith("https://")) {
return id;
}
if (id.includes("svelte")) {
return `https://cdn.skypack.dev/${id}`;
}
return `https://cdn.esm.sh/${id}`;
},
}),
denoLoader(),
svelte(),
compress(),
],
}).then((g: any) => g.generate({ format: "es" }));
const outpath = entryPath.replace(/(.*)\.tsx?/, "$1.bundle.js");
await Deno.writeTextFile(outpath, sourceGen.output[0].code);
}