{"id":25372,"library":"esbuild-plugin-minify-html","title":"esbuild-plugin-minify-html","description":"An esbuild plugin that imports HTML files as minified raw text strings at build time, using html-minifier-terser for minification. Version 0.1.2 is the current stable release, with infrequent updates. It differentiates itself from raw-text loaders by combining import and minification in one plugin, eliminating the need for a separate minification step. Ships TypeScript types and supports customizable minifier options like collapseWhitespace.","status":"active","version":"0.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/hatemhosny/esbuild-plugin-minify-html","tags":["javascript","esbuild","esbuild-plugin","html","raw","minify","typescript"],"install":[{"cmd":"npm install esbuild-plugin-minify-html","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-minify-html","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-minify-html","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for HTML minification","package":"html-minifier-terser","optional":false}],"imports":[{"note":"Package exports ESM default; CJS require works but may fail if bundler lacks ESM interop","wrong":"const minifyHTML = require('esbuild-plugin-minify-html')","symbol":"default (minifyHTML)","correct":"import minifyHTML from 'esbuild-plugin-minify-html'"},{"note":"The ?raw query suffix is required to trigger the plugin; TypeScript needs a module declaration for ?raw imports","wrong":"import content from './file.html'","symbol":"HTML file import with ?raw","correct":"import content from './file.html?raw'"},{"note":"The ?raw suffix must be included in the module declaration to match the import syntax","wrong":"declare module '*.html' { const src: string; export default src; }","symbol":"TypeScript module declaration","correct":"declare module '*.html?raw' { const src: string; export default src; }"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport minifyHTML from 'esbuild-plugin-minify-html';\n\nawait esbuild.build({\n  entryPoints: ['src/index.js'],\n  bundle: true,\n  outfile: 'dist/out.js',\n  plugins: [\n    minifyHTML({\n      collapseWhitespace: true,\n      removeComments: true,\n    }),\n  ],\n});","lang":"javascript","description":"Build script using esbuild with minifyHTML plugin to import and minify HTML files as raw text."},"warnings":[{"fix":"Always append ?raw to HTML import paths: import content from './file.html?raw'","message":"Query suffix ?raw is required on HTML imports; omitting it bypasses the plugin and may cause build errors or undefined imports.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Add a .d.ts file with: declare module '*.html?raw' { const src: string; export default src; }","message":"TypeScript users must add a module declaration for *.html?raw to avoid type errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Migrate to new package: npm install esbuild-plugin-minify-html and update imports","message":"Version 0.1.0 changed from esbuild-plugin-raw-css to esbuild-plugin-minify-html; all import paths and plugin API changed.","severity":"breaking","affected_versions":"0.0.x"},{"fix":"Refer to html-minifier-terser documentation and test minified output for correctness","message":"html-minifier-terser options are passed directly to the minifier; some options may break HTML semantics if misconfigured.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add minifyHTML plugin to esbuild.plugins array and ensure import path ends with ?raw.","cause":"Plugin not registered in esbuild configuration or ?raw suffix omitted.","error":"Error: No matching plugins for import \"*.html?raw\""},{"fix":"Place a .d.ts file in your project root with: declare module '*.html?raw' { const src: string; export default src; }","cause":"TypeScript does not recognize .html?raw imports without a module declaration.","error":"Cannot find module '*.html?raw' or its corresponding type declarations."},{"fix":"Run: npm install html-minifier-terser","cause":"Missing required peer dependency html-minifier-terser.","error":"Error: Cannot find module 'html-minifier-terser'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}