@swc/html

Installation

npm
yarn
pnpm
bun
deno
npm install -D @swc/html

Usage

minify() / minifySync()

If you are minifying a whole HTML document, you can use the minify() function.

import { 
function minify(content: string | Buffer, options?: Options): Promise<TransformOutput>
minify
} from '@swc/html';
const
const html: TransformOutput
html
= await
function minify(content: string | Buffer, options?: Options): Promise<TransformOutput>
minify
('<div>Hello, world!</div>', {
});

minifyFragment() / minifyFragmentSync()

If you are minifying a fragment of HTML, you can use the minifyFragment() function.

import { 
function minifyFragment(content: string | Buffer, options?: FragmentOptions): Promise<TransformOutput>
minifyFragment
} from '@swc/html';
const
const html: TransformOutput
html
= await
function minifyFragment(content: string | Buffer, options?: FragmentOptions): Promise<TransformOutput>
minifyFragment
('<div>Hello, world!</div>', {
});