-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
44 lines (38 loc) · 1.48 KB
/
build.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
33
34
35
36
37
38
39
40
41
42
43
44
import { $ } from "bun";
// Scripts
console.log("Building scripts...");
await Bun.build({
entrypoints: ["src/error.ts"],
minify: true,
outdir: "dist",
});
// HTML
console.log("\nBuilding pages...");
const html_filepaths_source = (await $`ls src/*.html`.text()).split("\n");
const html_minifier = require("html-minifier").minify;
for (const filepath_source of html_filepaths_source) {
if (filepath_source == "") { continue; }
console.log(filepath_source);
const filepath_target = "dist/" + filepath_source.substring(4);
const content_source = await Bun.file(filepath_source).text();
const content_target = html_minifier(content_source, {
removeComments: true,
removeCommentsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
});
await Bun.write(filepath_target, content_target);
}
// Styles
console.log("\nBuilding styles...");
const style_filepaths_source = (await $`ls src/*.scss`.text()).split("\n");
const scss_minifier = require("sass");
for (const filepath_source of style_filepaths_source) {
if (filepath_source == "") { continue; }
const filepath_target = filepath_source.replace(/^[^/]+\/(.+).scss$/, "dist/$1.css");
if (filepath_target == filepath_source) { continue; }
console.log(filepath_source);
const content_target = scss_minifier.compile(filepath_source, { style: "compressed" }).css;
await Bun.write(filepath_target, content_target);
}