You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { emptyDir } from "https://deno.land/std@0.162.0/fs/mod.ts";
|
|
import sass from "https://deno.land/x/denosass@1.0.6/mod.ts";
|
|
import { build, stop } from "https://deno.land/x/esbuild@v0.17.5/mod.js";
|
|
import { httpImports } from "https://deno.land/x/esbuild_plugin_http_imports@v1.3.0/index.ts";
|
|
import * as importMap from "npm:esbuild-plugin-import-map";
|
|
|
|
await emptyDir("./build");
|
|
|
|
const compiler = sass(["./frontend/style.scss"]);
|
|
|
|
compiler.to_file({
|
|
destDir: "./build/",
|
|
destFile: "style",
|
|
format: "compressed",
|
|
});
|
|
|
|
const denoJson = JSON.parse(await Deno.readTextFile("./deno.json"));
|
|
|
|
importMap.load(denoJson);
|
|
|
|
const res = await build({
|
|
entryPoints: ["./frontend/main.ts"],
|
|
write: true,
|
|
bundle: true,
|
|
outfile: "./build/app.js",
|
|
sourcemap: "inline",
|
|
plugins: [httpImports(), importMap.plugin()],
|
|
});
|
|
console.debug(res);
|
|
|
|
stop();
|
|
|
|
const bundleText = await Deno.readTextFile("./build/app.js");
|
|
const styleText = await Deno.readTextFile("./build/style.min.css");
|
|
|
|
const buildModuleText = (identsToValues: Record<string, string>) => {
|
|
let out = ``;
|
|
for (const k in identsToValues) {
|
|
const v = identsToValues[k];
|
|
|
|
out += `export const ${k} = atob("${btoa(v)}");`;
|
|
}
|
|
|
|
return out;
|
|
};
|
|
|
|
const moduleText = buildModuleText({
|
|
bundleText,
|
|
styleText,
|
|
mode: "dev",
|
|
});
|
|
|
|
await Deno.writeTextFile("./build/mod.ts", moduleText);
|