aboutsummaryrefslogtreecommitdiff
path: root/static/js/bundle.ts
blob: ac858c4bbcb6903b63eba51e6a84136438156395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { bundle } from "https://deno.land/x/emit@0.17.0/mod.ts";

function removeSourceMap(text): string {
  return text.replace(/^\/\/# sourceMappingURL.*$/gm, "").trim();
}

const entrypoint = await bundle(
  "./static/js/index.ts",
);

const output = removeSourceMap(entrypoint.code);
const file = Deno.cwd() + "/assets/js/index.js";
const fileSize = ((await Deno.stat(file)).size / 1024).toFixed(2) + "kB";

await Deno.writeTextFile(file, output, {});

console.log(
  `Bundle file:///${file}` +
    "\n" +
    `Emit   file:///${file} (${fileSize})`,
);