|
| 1 | +<div align="center"> |
| 2 | + <img height="200" src="images/plugin-logo.png"> |
| 3 | + <h1 align="center"> |
| 4 | + <a href="https://github.com/webdiscus/html-bundler-webpack-plugin">HTML Bundler Plugin for Webpack</a><br> |
| 5 | + <sub>All-in-one Web Bundler</sub><br> |
| 6 | + </h1> |
| 7 | +</div> |
| 8 | + |
| 9 | +[](https://www.npmjs.com/package/html-bundler-webpack-plugin 'download npm package') |
| 10 | +[](https://nodejs.org) |
| 11 | +[](https://webpack.js.org) |
| 12 | +[](https://github.com/webdiscus/html-bundler-webpack-plugin/actions/workflows/test.yml) |
| 13 | +[](https://codecov.io/gh/webdiscus/html-bundler-webpack-plugin) |
| 14 | +[](https://www.npmjs.com/package/html-bundler-webpack-plugin) |
| 15 | + |
| 16 | +> This plugin is all you need to generate a complete single- or multi-page website from your source assets. |
| 17 | +
|
| 18 | +The plugin automates the processing of source files such as JS/TS, SCSS, images and other assets referenced in an HTML or template file. |
| 19 | +This plugin will generate an HTML file containing all the necessary links to JS, CSS, images and other resources. |
| 20 | + |
| 21 | +## Why use the HTML Bundler Plugin? |
| 22 | + |
| 23 | +This plugin is a powerful alternative to [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin) and a replacement for many [plugins and loaders](#list-of-plugins). |
| 24 | + |
| 25 | +The HTML Bundler Plugin works a bit differently than `html-webpack-plugin`. |
| 26 | +It doesn't just inject JavaScript and CSS into an HTML. |
| 27 | +Instead, it resolves all the source files of the assets referenced directly in the template |
| 28 | +and ensures the generated HTML contains the correct output URLs of resources after Webpack processes them. |
| 29 | +Additionally, CSS extracted from styles imported in JS can be injected into HTML as a `<link>` tag or as an inlined CSS. |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +<h3 align="center"> |
| 34 | +📋 <a href="https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#contents">Table of Contents</a> 🚀<a href="https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#install">Install and Quick Start</a> 🖼 <a href="https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#usage-examples">Usage examples</a> |
| 35 | +</h3> |
| 36 | + |
| 37 | +--- |
| 38 | + |
| 39 | +## 💡 Highlights |
| 40 | + |
| 41 | +- An [entry point](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-entry) is any HTML template. **Start from HTML**, not from JS. |
| 42 | +- **Automatically** processes templates found in the [entry directory](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-entry-path). |
| 43 | +- Build-in support for [template engines](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#template-engine): [Eta](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-eta), [EJS](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-ejs), [Handlebars](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-handlebars), [Nunjucks](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-nunjucks), [Pug](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-pug), [Tempura](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-tempura), [TwigJS](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-twig), [LiquidJS](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#using-template-liquidjs). |
| 44 | +- Build-in support for **Markdown** `*.md` files in templates, see [Markdown demo](https://stackblitz.com/edit/markdown-to-html-webpack?file=webpack.config.js) in browser. |
| 45 | +- **Source files** of [`script`](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-js) and [`style`](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-css) can be specified directly in HTML: |
| 46 | + - `<link href="./style.scss" rel="stylesheet">`\ |
| 47 | + No longer need to define source style files in Webpack entry or import styles in JavaScript. |
| 48 | + - `<script src="./app.ts" defer="defer"></script>`\ |
| 49 | + No longer need to define source JavaScript files in Webpack entry. |
| 50 | +- **Resolves** [source files](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#loader-option-sources) of assets in [attributes](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#loader-option-sources-default) such as `href` `src` `srcset` using **relative path** or **alias**: |
| 51 | + - `<link href="../images/favicon.svg" type="image/svg" rel=icon />` |
| 52 | + - `<img src="@images/pic.png" srcset="@images/pic400.png 1x, @images/pic800.png 2x" />`\ |
| 53 | + Source files will be resolved, processed and auto-replaced with correct URLs in the generated HTML. |
| 54 | +- **Resolves** [route URLs](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-router) in `a.href`, useful for navigation in multi-pages. |
| 55 | +- **Inlines** [JS](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#recipe-inline-js), [CSS](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#recipe-inline-css) and [Images](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#recipe-inline-image) into HTML. See [how to inline all resources](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#recipe-inline-all-assets-to-html) into single HTML file. |
| 56 | +- Supports the [HMR for CSS](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-css-hot) to update CSS in browser without a full reload. |
| 57 | +- Watches for changes in the [data file](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-entry-data) linked to the template in the plugin option. |
| 58 | +- Generates the [preload](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-preload) tags for fonts, images, video, scripts, styles. |
| 59 | +- Generates the [integrity](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#option-integrity) attribute in the `link` and `script` tags. |
| 60 | +- Generates the [favicons](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#favicons-bundler-plugin) of different sizes for various platforms. |
| 61 | +- You can create custom plugins using the provided [Plugin Hooks](https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/README.md#plugin-hooks-and-callbacks). |
| 62 | +- Over 700 [tests](https://github.com/webdiscus/html-bundler-webpack-plugin/tree/master/test) for various use cases. |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +📖 See [full documentation on GitHub](https://github.com/webdiscus/html-bundler-webpack-plugin). |
0 commit comments