html-webpack-plugin

Generates and injects your webpack bundle tags into HTML files automatically, with zero configuration required.

Tool
npm
v5.6.8
10,718 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
60 /100 Good
Development Activity 32
Maintenance 24
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 78
Code Quality 80
Innovation 82
Learning Curve 80

html-webpack-plugin is the standard webpack plugin for generating the HTML files that load your bundled JavaScript and CSS. Instead of hand-editing script and link tags every time an output filename or content hash changes, the plugin watches the compilation’s chunks and entry points and injects the right tags automatically — with zero configuration needed for a simple single-page app.

Beyond the zero-config default, it supports custom EJS/Handlebars/Pug templates, per-entry filenames for multi-page builds, favicon handling, and a set of typed tapable hooks (beforeAssetTagGeneration, alterAssetTags, afterTemplateExecution, beforeEmit, and more) that let a large ecosystem of companion plugins — subresource integrity, CSP headers, favicon generation, asset inlining — extend its output without patching webpack itself.

What You Get

  • Zero-config HTML generation for single-page apps — works immediately after new HtmlWebpackPlugin()
  • Custom template support via EJS, Handlebars, Pug, or a raw loader for full control over markup
  • Multi-page output with per-entry filename functions and chunks/excludeChunks filtering
  • Automatic favicon copying and <link rel="icon"> injection
  • Six ordered tapable hooks for deep customization by companion plugins
  • Cached child compilation so unchanged output isn’t re-emitted on every rebuild

Common Use Cases

  • Single-page app builds - front-end teams building an SPA get an index.html with correctly hashed script/link tags emitted automatically on every build, no manual editing needed.
  • Multi-page/multi-entry sites - projects with several entry points use per-entry filename functions and chunks filtering to emit one HTML file per page from a single webpack config.
  • Custom branded templates - teams with existing HTML templates (EJS, Handlebars, Pug) plug them in via template/templateContent to keep their own markup while still getting automatic asset injection.
  • Building companion webpack plugins - plugin authors hook into beforeAssetTagGeneration, alterAssetTags, or beforeEmit to add SRI hashes, CSP meta tags, or inline critical CSS without forking core.

Under The Hood

Architecture

The main HtmlWebpackPlugin class in index.js (~1,568 lines) hooks into webpack’s compiler via apply(compiler) and exposes six ordered tapable AsyncSeriesWaterfallHooks (beforeAssetTagGeneration, alterAssetTags, alterAssetTagGroups, afterTemplateExecution, beforeEmit, afterEmit) through a static getCompilationHooks() keyed off a WeakMap<Compilation, Hooks> so multiple plugin instances share one hook registry per compilation. Actual HTML generation is delegated to lib/cached-child-compiler.js and lib/child-compiler.js, which spin up a webpack child compiler using NodeTemplatePlugin/NodeTargetPlugin/LoaderTargetPlugin/EntryPlugin to compile the user’s template into a runnable module and execute it in a VM context to produce the final HTML string; lib/chunksorter.js orders entries in the output and lib/html-tags.js models the injected script/link/meta tags as reusable objects. Because the tapable hooks are the plugin’s entire public extension surface, a large ecosystem of downstream plugins (subresource-integrity, favicon, CSP plugins) depends directly on this child-compiler abstraction remaining stable.

Tech Stack

Written as plain CommonJS JavaScript with @ts-check and a hand-authored typings.d.ts for consumer typing rather than being written in TypeScript directly, so the package ships raw source with no build/transpile step. Runtime dependencies are minimal and targeted: tapable for the hook system, lodash for template interpolation, html-minifier-terser for optional output minification, and pretty-error for readable compiler error output. webpack (^5.20) and @rspack/core are both declared as optional peer dependencies, reflecting a recent push to support Rspack alongside webpack. Tooling around the package is comprehensive: Jest for tests, ESLint + Prettier + cspell for linting, Husky/lint-staged/commitlint for commit hygiene, and standard-version for releases, all wired into GitHub Actions CI.

Code Quality

Test coverage is extensive — spec/basic.spec.js alone runs to nearly 3,900 lines covering broad permutations of plugin options and output, alongside dedicated suites for incremental/watch caching (caching.spec.js), hot module replacement behavior (hot.spec.js), and an example-build regression suite that diffs generated output against fixtures using dir-compare. Errors are handled explicitly and formatted through a dedicated lib/errors.js module rather than swallowed, and every source file uses @ts-check with JSDoc type annotations checked against typings.d.ts via a posttest tsc run, giving most of the safety of TypeScript without a compile step. Naming is consistent and CI enforces lint plus the full test suite on every change.

API Design The public surface is intentionally small: a single constructor option object covers the common cases with sane defaults, so a bare new HtmlWebpackPlugin() works with no configuration at all. Options like chunks, excludeChunks, chunksSortMode, and a function-valued filename cover the large majority of multi-entry scenarios without needing to escape into hook code, while the six documented tapable hooks (mirrored in both a JSDoc block in index.js and the Hooks namespace in typings.d.ts) give advanced users typed, ordered extension points. This combination of a low floor and a well-documented, typed extension ceiling is what has let a wide ecosystem of independent companion plugins build on it without needing to fork or monkey-patch core behavior.

Used by 37 apps in this directory

JavaScript
89%
GPL 3.0

Screenity

Productivity · Video Editors

18,806

Free, privacy-first Chrome screen recorder with real-time annotation, AI camera blur, and a built-in video editor — no sign-in or limits required.

View details
74
Repo Health
62
Technical
70
Dependency
Built with
JavaScript 89%
Updated 1 weeks ago
Python
57%
Other

Sentry

Analytics · Developer Tools · Monitoring

45,632

Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.

View details
95
Repo Health
80
Technical
66
Dependency
Built with
Python 57%
TypeScript 42%
Updated 5 days ago
TypeScript
61%
AGPL 3.0

Silex

Design Tools · No Code Platforms

3,015

Free, open-source visual website builder that exports clean HTML/CSS — no lock-in, no subscription, host anywhere

View details
89
Repo Health
68
Technical
67
Dependency
Built with
TypeScript 61%
Rust 15%
JavaScript 11%
Updated 6 days ago
TypeScript
83%
AGPL 3.0

Standard Notes

Note Taking

6,681

End-to-end encrypted notes and files — private by design, built to last, and fully self-hostable.

View details
89
Repo Health
83
Technical
68
Dependency
Built with
TypeScript 83%
JavaScript 14%
Updated 6 days ago
TypeScript
89%
Other

strapi

CMS

73,368

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
63
Dependency
Built with
TypeScript 89%
JavaScript 11%
Updated 6 days ago
JavaScript
93%
Apache 2.0

swagger-ui

Developer Tools

29,042

Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.

View details
98
Repo Health
83
Technical
62
Dependency
Built with
JavaScript 93%
Updated 6 days ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 5 days ago
TypeScript
41%
AGPL 3.0

Wiki.js

Collaboration · Knowledge Management

29,081

A modern, self-hosted wiki platform built on Node.js with a rich plugin ecosystem for authentication, search, storage, and rendering that adapts to any team's infrastructure.

View details
95
Repo Health
67
Technical
60
Dependency
Built with
TypeScript 41%
Vue 39%
JavaScript 16%
Updated 5 days ago
TypeScript
96%
GPL 3.0

Wire

Collaboration · Team Chat · Video Conferencing

1,192

Open source end-to-end encrypted messaging for teams and enterprises — self-host for complete control over your communications and data.

View details
93
Repo Health
8
Technical
68
Dependency
Built with
TypeScript 96%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers