2024-02-19 08:58:15 +04:00
|
|
|
import fs from 'node:fs/promises'
|
|
|
|
import { globby } from 'globby'
|
2024-05-06 22:59:16 +04:00
|
|
|
import { minify } from 'html-minifier-terser'
|
2024-02-19 08:58:15 +04:00
|
|
|
|
|
|
|
// 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
|
2024-05-06 23:06:52 +04:00
|
|
|
html = await minify(html, {
|
2024-02-19 08:58:15 +04:00
|
|
|
removeComments: true,
|
|
|
|
preserveLineBreaks: true,
|
2024-02-19 09:36:37 +04:00
|
|
|
collapseWhitespace: true,
|
|
|
|
minifyJS: true
|
2024-02-19 08:58:15 +04:00
|
|
|
})
|
|
|
|
await fs.writeFile(file, html)
|
|
|
|
})
|
|
|
|
)
|