Registry / devops / sveltekit-html-minifier

sveltekit-html-minifier

JSON →
library1.0.4jsnpmunverified

A SvelteKit adapter that minifies prerendered HTML output pages using html-minifier-terser. v1.0.4 stable. It wraps any existing adapter (e.g., @sveltejs/adapter-static) and runs minification after the default adapter finishes. Only works on prerendered pages; runtime-rendered pages are not minified. Supports custom build paths and minifier options. Ships TypeScript types. Active development.

npm install sveltekit-html-minifier
INSTALL
IMPORT
SIG · SVELTEKIT-HTML-MIN
S
sveltekit-html-minifier
devopsjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

htmlMinifierAdaptor
import htmlMinifierAdaptor from 'sveltekit-html-minifier'
const htmlMinifierAdaptor = require('sveltekit-html-minifier')
Package is ESM-only; CommonJS require will fail.
adapter
import adapter from '@sveltejs/adapter-static'
The default adapter is passed as the first argument to htmlMinifierAdaptor.
htmlMinifierOptions
import htmlMinifierAdaptor from 'sveltekit-html-minifier'; // options as second argument
import { htmlMinifierOptions } from 'sveltekit-html-minifier'
Options are passed as an object literal, not imported separately.

Configures SvelteKit to minify prerendered HTML using adapter-static as base.

// svelte.config.js import adapter from '@sveltejs/adapter-static'; import htmlMinifierAdaptor from 'sveltekit-html-minifier'; export default { kit: { adapter: htmlMinifierAdaptor( adapter({ pages: 'build', }), { pages: 'build', minifierOptions: { collapseWhitespace: true, removeComments: true, }, } ), }, };
Debug
Known issues
gotchaOnly minifies prerendered HTML pages; runtime-rendered pages are not minified.
fix
Ensure pages have `export const prerender = true;` and that prerendered output path matches the adapter's output.
affects: >=1.0.0
gotchaBuild path must match the adapter's output directory. Different adapters use different paths.
fix
Set `pages` option explicitly, e.g., for Cloudflare: `{ pages: '.svelte-kit/cloudflare' }`; for Vercel: `{ pages: '.svelte-kit/output/prerendered/pages' }`.
affects: >=1.0.0
gotchaThe default adapter (first argument) is executed first; only its prerendered output is minified.
fix
Place your primary adapter as the first argument; this adapter wraps and post-processes.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS `require()` with an ESM-only package.
fix
Use `import` syntax or change your project to ESM (add `"type": "module"` to package.json).
HTML not minified
Page is not prerendered or output path is incorrect.
fix
Ensure page has `export const prerender = true;` and the `pages` option matches your adapter's output folder.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
@sveltejs/kitrequiredPeer dependency required for SvelteKit adapter integration
html-minifier-terserrequiredUnderlying minification library
Agent activity
6 hits · last 30 days
node
6
Resources
sveltekit-html-minifier — npm install sveltekit-html-minifier · libregistry