-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.ts
More file actions
32 lines (25 loc) · 1.16 KB
/
bundle.ts
File metadata and controls
32 lines (25 loc) · 1.16 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
import { bundle } from "emit";
const bundleCode = async (file: string) => {
const url = new URL(import.meta.resolve(file));
const denoJsonUrl = new URL("./deno.json", import.meta.url);
const denoConfig = JSON.parse(await Deno.readTextFile(denoJsonUrl));
const { code } = await bundle(url, {
importMap: {
imports: denoConfig.imports ?? {},
},
});
// NOTE: Workaround トランスパイルしたら連想配列のキーにマルチバイト文字が含まれていてクオートされていない状態になってしまうので無理やり判定してクォート付与
const keyQuotedCode = code.replace(
/(\s)([a-zA-Z0-9_\uFF21-\uFF3A\uFF41-\uFF5A]*[\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\uFF66-\uFF9F\uFF10-\uFF19々]+[a-zA-Z0-9_\uFF21-\uFF3A\uFF41-\uFF5A]*)(:)/g,
'$1"$2"$3',
);
// NOTE: Workaround export ... も不要なため削除
const exportRemovedCode = keyQuotedCode.replace(
/(export { .+ };)$/gm,
"/* $1 */",
);
return exportRemovedCode;
};
const renderCode = await bundleCode("./render.ts");
const themeCode = await bundleCode("./theme.ts");
Deno.writeTextFile("./static/app.js", renderCode + "\n" + themeCode);