achat-maison-albi-fr/process-html.mjs
Emil Gulamov e3888b18cb Add HTML minification process and update dependencies
A new script for HTML minification has been added, which is run after the build process. Several dependencies were updated, including the Astro framework and its related plugins. The 'astro-critters' package and its usage in the Astro configuration were removed. A minor animation timing change was also made in the [...slug].astro file.
2024-02-19 08:58:15 +04:00

22 lines
No EOL
580 B
JavaScript

import fs from 'node:fs/promises'
import { globby } from 'globby'
import { minify } from 'html-minifier'
// Get all HTML files from the output directory
const path = './.vercel/output/static'
const files = await globby(`${path}/**/*.html`)
await Promise.all(
files.map(async (file) => {
console.log('Processing file:', file)
let html = await fs.readFile(file, 'utf-8')
// Minify the HTML
html = minify(html, {
removeComments: true,
preserveLineBreaks: true,
collapseWhitespace: true
})
await fs.writeFile(file, html)
})
)