mirror of
https://github.com/xHyroM/website.git
synced 2024-11-14 03:28:07 +01:00
28 lines
No EOL
1,013 B
JavaScript
28 lines
No EOL
1,013 B
JavaScript
import { minify } from "html-minifier";
|
|
import { writeFile, readFile } from "node:fs/promises";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
export default () => {
|
|
return {
|
|
name: "hyro-minify",
|
|
hooks: {
|
|
"astro:build:done": async (opts) => {
|
|
for (const route of opts.routes) {
|
|
const content = await readFile(fileURLToPath(route.distURL), "utf-8");
|
|
const minified = await minify(content, {
|
|
removeAttributeQuotes: true,
|
|
collapseWhitespace: true,
|
|
minifyCSS: true,
|
|
html5: true,
|
|
removeComments: true,
|
|
minifyJS: true,
|
|
minifyURLs: true,
|
|
});
|
|
|
|
await writeFile(fileURLToPath(route.distURL), minified, "utf-8");
|
|
console.log(`Minified ${route.distURL.pathname}`)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |