{"id":25287,"library":"esbuild-html-plugin","title":"esbuild-html-plugin","description":"An esbuild plugin that generates an HTML file with output URLs of bundled assets. Version 1.1.0, released as stable. It provides fine-grained control over HTML head and body elements through callback functions, allowing dynamic injection of CSS and JS references. Unlike alternative HTML plugins for esbuild, this one is minimalistic and avoids bundling HTML templates, focusing solely on generating a simple HTML file with asset URLs. No HTML minification is included since v1.1.0. The package is ESM-only, small, and has no runtime dependencies.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/clebert/esbuild-html-plugin","tags":["javascript"],"install":[{"cmd":"npm install esbuild-html-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-html-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-html-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only; require() will fail.","wrong":"const htmlPlugin = require('esbuild-html-plugin')","symbol":"htmlPlugin","correct":"import { htmlPlugin } from 'esbuild-html-plugin'"},{"note":"Named export, not default. v1.0.1 added types to package.json, so TypeScript works.","wrong":"import htmlPlugin from 'esbuild-html-plugin'","symbol":"htmlPlugin","correct":"import { htmlPlugin } from 'esbuild-html-plugin'"},{"note":"Available as a type export for TypeScript users.","wrong":"","symbol":"HtmlPluginOptions","correct":"import type { HtmlPluginOptions } from 'esbuild-html-plugin'"}],"quickstart":{"code":"import * as esbuild from 'esbuild';\nimport { htmlPlugin } from 'esbuild-html-plugin';\n\nawait esbuild.build({\n  entryPoints: ['app.ts'],\n  bundle: true,\n  outdir: 'dist',\n  publicPath: '/static',\n  plugins: [\n    htmlPlugin({\n      outfile: 'index.html',\n      createHeadElements: () => [\n        `<meta charset=\"utf-8\" />`,\n        `<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />`,\n        `<title>Example</title>`,\n      ],\n      createBodyElements: (outputUrls) =>\n        outputUrls\n          .filter((url) => url.endsWith('.js'))\n          .map((url) => `<script src=\"${url}\"></script>`),\n    }),\n  ],\n});","lang":"typescript","description":"Builds an esbuild bundle and generates an index.html with script tags for JS outputs."},"warnings":[{"fix":"Remove any minification options. If needed, use a separate minification step.","message":"HTML minification feature removed in v1.1.0","severity":"breaking","affected_versions":"<=1.0.1"},{"fix":"Change import to named export.","message":"Default export removed; use named export htmlPlugin","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Ensure outfile is set and esbuild's outdir or outfile is configured.","message":"outfile must be provided; outdir or esbuild's outfile must be set or the HTML won't be generated","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Handle URLs as provided; use publicPath to control prefix.","message":"createHeadElements and createBodyElements receive output URLs; they may be absolute or relative depending on publicPath","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install esbuild-html-plugin' and use 'import' syntax.","cause":"Missing installation or ESM-only package used with require()","error":"Error: Cannot find module 'esbuild-html-plugin'"},{"fix":"Change to 'import { htmlPlugin } from 'esbuild-html-plugin''.","cause":"Default import used instead of named import","error":"TypeError: htmlPlugin is not a function"},{"fix":"Ensure htmlPlugin is called: htmlPlugin({ outfile: 'index.html' }).","cause":"Misconfigured plugin parameter; likely passed undefined or wrong shape","error":"Error: The plugin \"html-plugin\" must be an object with a \"name\" and \"setup\" function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}