[![npm][npm]][npm-url]
[![node][node]][node-url]
[![tests][tests]][tests-url]
<img width="100" height="100" title="Webpack Plugin" src="http://michael-ciniawsky.github.io/postcss-load-plugins/logo.svg">
Plugin that simplifies creation of HTML files to serve your bundles
npm i --save-dev html-webpack-plugin
yarn add --dev html-webpack-plugin
npm i --save-dev html-webpack-plugin@4
yarn add --dev html-webpack-plugin@4
This is a webpack plugin that simplifies creation of HTML files to serve your webpack bundles. This is especially useful for webpack bundles that include a hash in the filename which changes every compilation. You can either let the plugin generate an HTML file for you, supply
your own template using lodash templates or use your own loader.
Thanks for supporting the ongoing improvements to the html-webpack-plugin!
The html-webpack-plugin works without configuration.
It's a great addition to the ⚙️ webpack-config-plugins.
The html-webpack-plugin provides hooks to extend it to your needs. There are already some really powerful plugins which can be integrated with zero configuration
head or body (different locations ) of same html document.<link rel='preload'> and <link rel='prefetch'><link /> tags to have their media attribute set automatically; useful for providing specific desktop/mobile/print etc. stylesheets that the browser will conditionally downloadmeta tag to the HTML output. A strict CSP is specifically efficient against XSS attacks.nomodule attribute to specific injected scripts, which prevents the scripts from being loaded by newer browsers. Good for limiting loads of polyfills.The plugin will generate an HTML5 file for you that includes all your webpack
bundles in the head using script tags. Just add the plugin to your webpack
config as follows:
webpack.config.js
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: "index.js",
output: {
path: __dirname + "/dist",
filename: "index_bundle.js",
},
plugins: [new HtmlWebpackPlugin()],
};
This will generate a file dist/index.html containing the following
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Webpack App</title>
<script defer src="https://github.com/jantimon/html-webpack-plugin/raw/v5.6.7/index_bundle.js"></script>
</head>
<body></body>
</html>
If you have multiple webpack entry points, they will all be included with script tags in the generated HTML.
If you have any CSS assets in webpack's output (for example, CSS extracted with the mini-css-extract-plugin)
then these will be included with <link> tags in the HTML head.
If you have plugins that make use of it, html-webpack-plugin should be ordered first before any of the integrated Plugins.
You can pass a hash of configuration options to html-webpack-plugin.
Allowed values are as follows:
| Name | Type | Default | Description |
|---|---|---|---|
title |
{String} |
Webpack App |
The title to use for the generated HTML document |
filename |
{String\|Function} |
'index.html' |
The file to write the HTML to. Defaults to index.html. You can specify a subdirectory here too (eg: assets/admin.html). The [name] placeholder will be replaced with the entry name. Can also be a function e.g. (entryName) => entryName + '.html'. |
template |
{String} |
`` | webpack relative or absolute path to the template. By default it will use src/index.ejs if it exists. Please see the docs for details |
templateContent |
{string\|Function\|false} |
false | Can be used instead of template to provide an inline template - please read the Writing Your Own Templates section |
templateParameters |
{Boolean\|Object\|Function} |
false |
Allows to overwrite the parameters used in the template - see [example](ht |
$ claude mcp add html-webpack-plugin \
-- python -m otcore.mcp_server <graph>