Skip to content

Commit 9443a4c

Browse files
committed
feat: integrate HTML minification and update CSS build process
1 parent a81c78e commit 9443a4c

File tree

3 files changed

+49
-67
lines changed

3 files changed

+49
-67
lines changed

_build_scripts/build-component.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
22
import { copy } from "https://deno.land/[email protected]/fs/mod.ts";
3-
import { minify as minifyCss } from "https://esm.sh/[email protected]";
3+
import init, {minify} from "https://wilsonl.in/minify-html/deno/0.9.2/index.js";
4+
5+
await init();
6+
const encoder = new TextEncoder();
7+
const decoder = new TextDecoder();
48

59
export async function buildComponent(componentName: string) {
610
console.log(`Building ${componentName}`);
@@ -47,6 +51,11 @@ async function copy_files(componentName: string) {
4751
await copyCSSFiles(`${srcFolder}/${entry.name}`, `${distFolder}/${entry.name}`);
4852
continue;
4953
}
54+
55+
if (entry.name.endsWith(".html")) {
56+
await copyHTMLFiles(`${srcFolder}/${entry.name}`, `${distFolder}/${entry.name}`);
57+
continue;
58+
}
5059

5160
const srcPath = `${srcFolder}/${entry.name}`;
5261
const distPath = `${distFolder}/${entry.name}`;
@@ -56,12 +65,26 @@ async function copy_files(componentName: string) {
5665

5766
async function copyCSSFiles(srcFile: string, distFile: string) {
5867
const css = await Deno.readTextFile(srcFile);
59-
const result = await minifyCss(css);
60-
await Deno.writeTextFile(distFile, result.css);
68+
69+
const result = await esbuild.transform(css, {
70+
loader: "css",
71+
minify: true,
72+
});
73+
74+
await Deno.writeTextFile(distFile, result.code);
6175
}
6276

63-
async function copyHTMLFiles(srcFolder: string, distFolder: string) {
77+
async function copyHTMLFiles(srcFolder: string, distFile: string) {
78+
const html = await Deno.readTextFile(srcFolder);
79+
80+
const result = decoder.decode(minify(encoder.encode(html), {
81+
minify_css: true,
82+
minify_js: true,
83+
do_not_minify_doctype: true,
84+
keep_closing_tags: true
85+
}));
6486

87+
await Deno.writeTextFile(distFile, result);
6588
}
6689

6790
async function copyFilesToFolder(sourceDir: string, targetDir: string) {

deno.lock

Lines changed: 21 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1 @@
1-
:host {
2-
display: block;
3-
box-sizing: border-box;
4-
width: 1.5rem;
5-
height: 1.5rem;
6-
}
7-
8-
.rotate {
9-
animation: rotate 2s linear infinite;
10-
}
11-
12-
@keyframes rotate {
13-
from {
14-
transform: rotate(0deg);
15-
}
16-
to {
17-
transform: rotate(360deg);
18-
}
19-
}
20-
21-
.success {
22-
fill: green;
23-
}
24-
25-
.error {
26-
fill: red;
27-
}
28-
1+
:host{display:block;box-sizing:border-box;width:1.5rem;height:1.5rem}.rotate{animation:rotate 2s linear infinite}@keyframes rotate{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.success{fill:green}.error{fill:red}

0 commit comments

Comments
 (0)