@svackages/sveltkit-hook-html-minifier
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

svackage logo

npm version license

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

Readme

Keywords

none

Package Sidebar

Install

npm i @svackages/sveltkit-hook-html-minifier

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

6.41 kB

Total Files

5

Last publish

Collaborators

  • d.reitzner