An Vite/Rollup/Webpack/esbuild/Rspack plugin to minify HTML template literal strings.
Not yet well tested and not recommended for production.
- This plugin uses
@tdewolff/minify
to get significant performance gains in complex projects.- Try it for yourself! Clone and run
pnpm bench
- Try it for yourself! Clone and run
- Use unplugin to support multiple bundlers at the same time.
pnpm add -D unplugin-tdewolff-minify-html-literals @tdewolff/minify # pnpm
# yarn add -D unplugin-tdewolff-minify-html-literals @tdewolff/minify # yarn
# npm i -D unplugin-tdewolff-minify-html-literals @tdewolff/minify # npm
// vite.config.ts
import { defineConfig } from 'vite'
import minifyHTML from 'unplugin-tdewolff-minify-html-literals/vite'
export default defineConfig({
plugins: [
minifyHTML({ /* options */ }),
],
})
// rollup.config.js
import minifyHTML from 'unplugin-tdewolff-minify-html-literals/rollup'
export default {
plugins: [
minifyHTML({ /* options */ }),
],
}
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-tdewolff-minify-html-literals/webpack')({ /* options */ })
]
}
// esbuild.config.js
import { build } from 'esbuild'
import minifyHTML from 'unplugin-tdewolff-minify-html-literals/esbuild'
build({
plugins: [minifyHTML({ /* options */ })],
})
// rspack.config.js
module.exports = {
plugins: [
require('unplugin-tdewolff-minify-html-literals/rspack')({ /* options */ }),
],
}
import { defineConfig } from 'vite'
import minifyHTML from 'unplugin-tdewolff-minify-html-literals/vite'
export default defineConfig({
plugins: [
minifyHTML({
// minimatch of files to minify
include: [],
// minimatch of files not to minify
exclude: [],
// @tdewolff/minify config
// https://www.npmjs.com/package/@tdewolff/minify#usage
config: undefined,
}),
],
})
- The minify function uses the
parse-literals
library and some code fromminify-html-literals
, marked in the source code.