0.0.2 • Published 2 years ago
@svackages/sveltkit-hook-html-minifier v0.0.2
sveltkit-hook-html-minifier
⚠ This might change a bit with SvelteKit 1.0 ⚠
A sveltkit hook that wrapps html-minifier
How to use
Single hook
import { htmlMinifierHook } from "@svackages/sveltkit-hook-html-minifier";
/** @type {import('@sveltejs/kit').Handle} */
export const handle = htmlMinifierHook;
import { htmlMinifierHook } from "@svackages/sveltkit-hook-html-minifier";
import type { Handle } from "@sveltejs/kit";
export const handle: Handle = htmlMinifierHook;
Single hook with options
import { htmlMinifierHook } from "@svackages/sveltkit-hook-html-minifier";
import { prerendering } from '$app/environment';
const minifierOptions = {
removeAttributeQuotes: true,
};
/** @type {import('@sveltejs/kit').Handle} */
export const handle = ({ event, resolve }) => htmlMinifierHook({ event, resolve, minifierOptions, prerendering});
import { htmlMinifierHook } from "@svackages/sveltkit-hook-html-minifier";
import { prerendering } from '$app/environment';
import type { Handle } from "@sveltejs/kit";
const minifierOptions = {
removeAttributeQuotes: true,
};
export const handle: Handle = ({ event, resolve }) => htmlMinifierHook({ event, resolve, minifierOptions, prerendering});
Sequence
import { sequence } from '@sveltejs/kit/hooks';
import { htmlMinifierHook } from "@svackages/sveltkit-hook-html-minifier";
// Add htmlMinifierHook at the end
/** @type {import('@sveltejs/kit').Handle} */
export const handle: Handle = sequence(someOtherHook, htmlMinifierHook);
import { sequence } from '@sveltejs/kit/hooks';
import { htmlMinifierHook } from "@svackages/sveltkit-hook-html-minifier";
import type { Handle } from "@sveltejs/kit";
// Add htmlMinifierHook at the end
export const handle: Handle = sequence(someOtherHook, htmlMinifierHook);
Default Options
const defaultMinifierOptions = {
collapseBooleanAttributes: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
html5: true,
ignoreCustomComments: [/^#/],
minifyCSS: true,
minifyJS: false,
removeAttributeQuotes: true,
removeComments: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
sortAttributes: true,
sortClassName: true,
};
To see all options take a look at the html-minifier docs