pages-landing-page/src/hooks.server.ts
Sam Therapy 399c593df4
All checks were successful
Build & Deploy / build (push) Successful in 31s
Lint
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2024-04-03 17:16:49 +02:00

35 lines
848 B
TypeScript

import { minify } from 'html-minifier-terser';
import { building } from '$app/environment';
const minification_options = {
collapseBooleanAttributes: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
html5: true,
ignoreCustomComments: [/^#/],
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true
};
/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) {
let page = '';
return resolve(event, {
transformPageChunk: ({ html, done }) => {
page += html;
if (done) {
return building ? minify(page, minification_options) : page;
}
}
});
}