-
Notifications
You must be signed in to change notification settings - Fork 0
/
astro.config.ts
48 lines (46 loc) · 1.35 KB
/
astro.config.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
45
46
47
48
// Full Astro Configuration API Documentation:
// https://docs.astro.build/reference/configuration-reference
// @ts-check
import { defineConfig } from "astro/config";
import { minifyHtml } from "./scripts/minify-html";
import { minifyFont } from "./scripts/minify-font";
import { extractCharsFromHtml } from "./scripts/extract-chars-from-html";
export default defineConfig({
outDir: "./public",
publicDir: "./src/public/",
site: "https://garin.dev",
vite: { build: { assetsInlineLimit: 0 } },
adapter: {
name: "minify",
hooks: {
"astro:build:done": async ({ routes, dir }) => {
const paths = routes
.filter((route) => route.type === "page")
.map(({ distURL }) => distURL)
.filter((url): url is URL => typeof url !== "undefined")
.map((url) => url.pathname);
await Promise.all([
extractCharsFromHtml(
paths,
(node) => !node.attrs?.class?.includes("font-semibold"),
).then((chars) =>
minifyFont(chars, {
src: dir.pathname + "_astro/*-400*.otf",
dest: dir.pathname + "_astro/",
}),
),
extractCharsFromHtml(
paths,
(node) => !!node.attrs?.class?.includes("font-semibold"),
).then((chars) =>
minifyFont(chars, {
src: dir.pathname + "_astro/*-600*.otf",
dest: dir.pathname + "_astro/",
}),
),
minifyHtml(paths),
]);
},
},
},
});