/unplugin-tdewolff-minify-html-literals

🗜️ An Vite/Rollup/Webpack/esbuild/Rspack plugin to minify HTML template literal strings.

Primary LanguageTypeScriptMIT LicenseMIT

unplugin-tdewolff-minify-html-literals

npm minified size downloads

An Vite/Rollup/Webpack/esbuild/Rspack plugin to minify HTML template literal strings.

Not yet well tested and not recommended for production.

Features

  • This plugin uses @tdewolff/minify to get significant performance gains in complex projects.
    • Try it for yourself! Clone and run pnpm bench
  • Use unplugin to support multiple bundlers at the same time.

Usage

Install

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

Configuration

Vite
// vite.config.ts
import { defineConfig } from 'vite'
import minifyHTML from 'unplugin-tdewolff-minify-html-literals/vite'

export default defineConfig({
  plugins: [
    minifyHTML({ /* options */ }),
  ],
})
Rollup
// rollup.config.js
import minifyHTML from 'unplugin-tdewolff-minify-html-literals/rollup'

export default {
  plugins: [
    minifyHTML({ /* options */ }),
  ],
}
Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-tdewolff-minify-html-literals/webpack')({ /* options */ })
  ]
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'
import minifyHTML from 'unplugin-tdewolff-minify-html-literals/esbuild'

build({
  plugins: [minifyHTML({ /* options */ })],
})
Rspack
// rspack.config.js
module.exports = {
  plugins: [
    require('unplugin-tdewolff-minify-html-literals/rspack')({ /* options */ }),
  ],
}

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,
    }),
  ],
})

Credits