Détail du package

html-webpack-plugin

jantimon53.5mMIT5.6.3

Simplifies creation of HTML files to serve your webpack bundles

webpack, plugin, html, html-webpack-plugin

readme

npm node npm tests Backers on Open Collective Sponsors on Open Collective

HTML Webpack Plugin

Plugin that simplifies creation of HTML files to serve your bundles

Install

Webpack 5

  npm i --save-dev html-webpack-plugin
  yarn add --dev html-webpack-plugin

Webpack 4

  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.

Sponsors

Thanks for supporting the ongoing improvements to the html-webpack-plugin!

Zero Config

The html-webpack-plugin works without configuration.
It's a great addition to the ⚙️ webpack-config-plugins.

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

Usage

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="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.

Options

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
inject `{Boolean\ String}` true `true \ \ 'head' \ \ 'body' \ \ falseInject all assets into the giventemplateortemplateContent. When passing'body'all javascript resources will be placed at the bottom of the body element.'head'will place the scripts in the head element. Passingtruewill add it to the head/body depending on thescriptLoadingoption. Passingfalse` will disable automatic injections. - see the inject:false example
publicPath `{String\ 'auto'}` 'auto' The publicPath used for script and link tags
scriptLoading `{'blocking'\ 'defer'\ 'module'\ 'systemjs-module'}` 'defer' Modern browsers support non blocking javascript loading ('defer') to improve the page startup performance. Setting to 'module' adds attribute type="module". This also implies "defer", since modules are automatically deferred.
favicon {String} `` Adds the given favicon path to the output HTML
meta {Object} {} Allows to inject meta-tags. E.g. meta: {viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no'}
base `{Object\ String\ false}` false Inject a base tag. E.g. base: "https://example.com/path/page.html
minify `{Boolean\ Object}` true if mode is 'production', otherwise false Controls if and in what ways the output should be minified. See minification below for more details.
hash {Boolean} false If true then append a unique webpack compilation hash to all included scripts and CSS files (i.e. main.js?hash=compilation_hash). This is useful for cache busting
cache {Boolean} true Emit the file only if it was changed
showErrors {Boolean} true Errors details will be written into the HTML page
chunks {?} ? Allows you to add only some chunks (e.g only the unit-test chunk)
chunksSortMode `{String\ Function}` auto Allows to control how chunks should be sorted before they are included to the HTML. Allowed values are `'none' \ 'auto' \ 'manual' \ {Function}`
excludeChunks {Array.<string>} `` Allows you to skip some chunks (e.g don't add the unit-test chunk)
xhtml {Boolean} false If true render the link tags as self-closing (XHTML compliant)

Here's an example webpack config illustrating how to use these options

webpack.config.js

{
  entry: 'index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'index_bundle.js'
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'My App',
      filename: 'assets/admin.html'
    })
  ]
}

Generating Multiple HTML Files

To generate more than one HTML file, declare the plugin more than once in your plugins array

webpack.config.js

{
  entry: 'index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'index_bundle.js'
  },
  plugins: [
    new HtmlWebpackPlugin(), // Generates default index.html
    new HtmlWebpackPlugin({  // Also generate a test.html
      filename: 'test.html',
      template: 'src/assets/test.html'
    })
  ]
}

Writing Your Own Templates

If the default generated HTML doesn't meet your needs you can supply your own template. The easiest way is to use the template option and pass a custom HTML file. The html-webpack-plugin will automatically inject all necessary CSS, JS, manifest and favicon files into the markup.

Details of other template loaders are documented here.

plugins: [
  new HtmlWebpackPlugin({
    title: "Custom template",
    // Load a custom template (lodash by default)
    template: "index.html",
  }),
];

index.html

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title><%= htmlWebpackPlugin.options.title %></title>
  </head>
  <body></body>
</html>

If you already have a template loader, you can use it to parse the template. Please note that this will also happen if you specify the html-loader and use .html file as template.

webpack.config.js

module: {
  loaders: [
    { test: /\.hbs$/, loader: "handlebars-loader" }
  ]
},
plugins: [
  new HtmlWebpackPlugin({
    title: 'Custom template using Handlebars',
    template: 'index.hbs'
  })
]

You can use the lodash syntax out of the box. If the inject feature doesn't fit your needs and you want full control over the asset placement use the default template of the html-webpack-template project as a starting point for writing your own.

The following variables are available in the template by default (you can extend them using the templateParameters option):

  • htmlWebpackPlugin: data specific to this plugin

    • htmlWebpackPlugin.options: the options hash that was passed to the plugin. In addition to the options actually used by this plugin, you can use this hash to pass arbitrary data through to your template.

    • htmlWebpackPlugin.tags: the prepared headTags and bodyTags Array to render the <base>, <meta>, <script> and <link> tags. Can be used directly in templates and literals. For example:

      <html>
        <head>
          <%= htmlWebpackPlugin.tags.headTags %>
        </head>
        <body>
          <%= htmlWebpackPlugin.tags.bodyTags %>
        </body>
      </html>
      
    • htmlWebpackPlugin.files: direct access to the files used during the compilation.

      publicPath: string;
      js: string[];
      css: string[];
      manifest?: string;
      favicon?: string;
      
  • webpackConfig: the webpack configuration that was used for this compilation. This can be used, for example, to get the publicPath (webpackConfig.output.publicPath).

  • compilation: the webpack compilation object. This can be used, for example, to get the contents of processed assets and inline them directly in the page, through compilation.assets[...].source() (see the inline template example).

The template can also be directly inlined directly into the options object.
⚠️ templateContent does not allow to use webpack loaders for your template and will not watch for template file changes

webpack.config.js

new HtmlWebpackPlugin({
  templateContent: `
    <html>
      <body>
        <h1>Hello World</h1>
      </body>
    </html>
  `,
});

The templateContent can also access all templateParameters values.
⚠️ templateContent does not allow to use webpack loaders for your template and will not watch for template file changes

webpack.config.js

new HtmlWebpackPlugin({
  inject: false,
  templateContent: ({ htmlWebpackPlugin }) => `
    <html>
      <head>
        ${htmlWebpackPlugin.tags.headTags}
      </head>
      <body>
        <h1>Hello World</h1>
        ${htmlWebpackPlugin.tags.bodyTags}
      </body>
    </html>
  `,
});

Filtering Chunks

To include only certain chunks you can limit the chunks being used

webpack.config.js

plugins: [
  new HtmlWebpackPlugin({
    chunks: ["app"],
  }),
];

It is also possible to exclude certain chunks by setting the excludeChunks option

webpack.config.js

plugins: [
  new HtmlWebpackPlugin({
    excludeChunks: ["dev-helper"],
  }),
];

Minification

If the minify option is set to true (the default when webpack's mode is 'production'), the generated HTML will be minified using html-minifier-terser and the following options:

{
  collapseWhitespace: true,
  keepClosingSlash: true,
  removeComments: true,
  removeRedundantAttributes: true,
  removeScriptTypeAttributes: true,
  removeStyleLinkTypeAttributes: true,
  useShortDoctype: true
}

To use custom html-minifier options pass an object to minify instead. This object will not be merged with the defaults above.

To disable minification during production mode set the minify option to false.

Meta Tags

If the meta option is set the html-webpack-plugin will inject meta tags.
For the default template the html-webpack-plugin will already provide a default for the viewport meta tag.

Please take a look at this well maintained list of almost all possible meta tags.

name/content meta tags

Most meta tags are configured by setting a name and a content attribute.
To add those use a key/value pair:

webpack.config.js

plugins: [
  new HtmlWebpackPlugin({
    meta: {
      viewport: "width=device-width, initial-scale=1, shrink-to-fit=no",
      // Will generate: <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      "theme-color": "#4285f4",
      // Will generate: <meta name="theme-color" content="#4285f4">
    },
  }),
];

Simulate http response headers

The http-equiv attribute is essentially used to simulate a HTTP response header.
This format is supported using an object notation which allows you to add any attribute:

webpack.config.js

plugins: [
  new HtmlWebpackPlugin({
    meta: {
      "Content-Security-Policy": {
        "http-equiv": "Content-Security-Policy",
        content: "default-src https:",
      },
      // Will generate: <meta http-equiv="Content-Security-Policy" content="default-src https:">
      // Which equals to the following http header: `Content-Security-Policy: default-src https:`
      "set-cookie": {
        "http-equiv": "set-cookie",
        content: "name=value; expires=date; path=url",
      },
      // Will generate: <meta http-equiv="set-cookie" content="value; expires=date; path=url">
      // Which equals to the following http header: `set-cookie: value; expires=date; path=url`
    },
  }),
];

Base Tag

When the base option is used, html-webpack-plugin will inject a base tag. By default, a base tag will not be injected.

The following two are identical and will both insert <base href="http://example.com/some/page.html">:

new HtmlWebpackPlugin({
  base: "http://example.com/some/page.html",
});
new HtmlWebpackPlugin({
  base: { href: "http://example.com/some/page.html" },
});

The target can be specified with the corresponding key:

new HtmlWebpackPlugin({
  base: {
    href: "http://example.com/some/page.html",
    target: "_blank",
  },
});

which will inject the element <base href="http://example.com/some/page.html" target="_blank">.

Long Term Caching

For long term caching add contenthash to the filename.

Example:

plugins: [
  new HtmlWebpackPlugin({
    filename: "index.[contenthash].html",
  }),
];

contenthash is the hash of the content of the output file.

Refer webpack's Template Strings for more details

Events

To allow other plugins to alter the HTML this plugin executes tapable hooks.

The lib/hooks.js contains all information about which values are passed.

Concept flow uml

beforeAssetTagGeneration hook

    AsyncSeriesWaterfallHook<{
      assets: {
        publicPath: string,
        js: Array<{string}>,
        css: Array<{string}>,
        favicon?: string | undefined,
        manifest?: string | undefined
      },
      outputName: string,
      plugin: HtmlWebpackPlugin
    }>

alterAssetTags hook

    AsyncSeriesWaterfallHook<{
      assetTags: {
        scripts: Array<HtmlTagObject>,
        styles: Array<HtmlTagObject>,
        meta: Array<HtmlTagObject>,
      },
      publicPath: string,
      outputName: string,
      plugin: HtmlWebpackPlugin
    }>

alterAssetTagGroups hook

    AsyncSeriesWaterfallHook<{
      headTags: Array<HtmlTagObject | HtmlTagObject>,
      bodyTags: Array<HtmlTagObject | HtmlTagObject>,
      publicPath: string,
      outputName: string,
      plugin: HtmlWebpackPlugin
    }>

afterTemplateExecution hook

    AsyncSeriesWaterfallHook<{
      html: string,
      headTags: Array<HtmlTagObject | HtmlTagObject>,
      bodyTags: Array<HtmlTagObject | HtmlTagObject>,
      outputName: string,
      plugin: HtmlWebpackPlugin,
    }>

beforeEmit hook

    AsyncSeriesWaterfallHook<{
      html: string,
      outputName: string,
      plugin: HtmlWebpackPlugin,
    }>

afterEmit hook

    AsyncSeriesWaterfallHook<{
      outputName: string,
      plugin: HtmlWebpackPlugin
    }>

Example implementation: webpack-subresource-integrity

plugin.js

// If your plugin is direct dependent to the html webpack plugin:
const HtmlWebpackPlugin = require("html-webpack-plugin");
// If your plugin is using html-webpack-plugin as an optional dependency
// you can use https://github.com/tallesl/node-safe-require instead:
const HtmlWebpackPlugin = require("safe-require")("html-webpack-plugin");

class MyPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap("MyPlugin", (compilation) => {
      console.log("The compiler is starting a new compilation...");

      // Static Plugin interface |compilation |HOOK NAME | register listener
      HtmlWebpackPlugin.getCompilationHooks(compilation).beforeEmit.tapAsync(
        "MyPlugin", // <-- Set a meaningful name here for stacktraces
        (data, cb) => {
          // Manipulate the content
          data.html += "The Magic Footer";
          // Tell webpack to move on
          cb(null, data);
        },
      );
    });
  }
}

module.exports = MyPlugin;

webpack.config.js

plugins: [new MyPlugin({ options: "" })];

Note that the callback must be passed the HtmlWebpackPluginData in order to pass this onto any other plugins listening on the same beforeEmit event

Maintainers


Jan Nicklas

Thomas Sileghem

Backers

Thank you to all our backers!
If you want to support the project as well become a sponsor or a a backer.

Contributors

This project exists thanks to all the people who contribute.

You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature should be covered by tests.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

5.6.3 (2024-10-23)

Bug Fixes

5.6.2 (2024-10-17)

Bug Fixes

5.6.1 (2024-10-17)

Bug Fixes

  • avoid importing all of lodash (#1864) (2caf5db)
  • don't use initialize hooks to allow dynamic plugin injection (ae85878)
  • handle childCompilation.errors being an iterator rather than array (#1863) (4c0c894)

5.6.0 (2023-12-19)

Features

  • add @rspack/core as an optional peer dependency (#1829) (56ff3ae)
  • Added support type=systemjs-module via the scriptLoading option (#1822) (7effc30)

Bug Fixes

5.5.4 (2023-12-06)

Bug Fixes

5.5.3 (2023-06-10)

Bug Fixes

5.5.2 (2023-06-08)

Bug Fixes

5.5.1 (2023-04-15)

Bug Fixes

  • perf: defer loading of pretty-error to improve startup time (#1789) (988709d)

5.5.0 (2021-10-25)

Features

  • Support type=module via scriptLoading option (1e42625), closes #1663

5.4.0 (2021-10-15)

Features

5.3.2 (2021-06-22)

Bug Fixes

  • update lodash and pretty error (9c7fba0

5.3.1 (2021-03-09)

Bug Fixes

  • remove loader-utils from plugin core (82d0ee8)

5.3.0 (2021-03-07)

Features

  • allow to modify the interpolation options in webpack config (d654f5b)
  • drop loader-utils dependency (41d7a50)

5.2.0 (2021-02-19)

Features

5.1.0 (2021-02-12)

Features

  • omit html tag attribute with null/undefined/false value (aa6e78d), closes #1598

5.0.0 (2021-02-03)

⚠ BREAKING CHANGES

  • Drop support for webpack 4 and node <= 10 - For older webpack or node versions please use html-webpack-plugin 4.x
  • Entry javascript resources are now being loaded deferred in the <head> tag to improve the page load performance by default - You can set the scriptLoading option to 'blocking' to keep the previous behaviour
  • Setting publicPath to '' (an empty string) will no longer calculate a relative path from the html file to the assets anymore - You can set the publicPath option to 'auto' to keep the previous behaviour
  • Plugins for html-webpack-plugin which add additional assetTags should provide a meta attribute
  • Drop support for appcache-webpack-plugin

Features

  • drop webpack 4 and node <= 10 support to make use of the latest APIs (b7a9e8f)
  • use the new webpack 5 APIs and create html files during the new webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS compilation stage (8964bc4, b6895cb, a97234e, 1b59e09, 4fca596, ed64a6b, 86245db, 50b3bec, c697725)
  • allow generating one file per chunk with the new '[name]' placeholder for the filename option (cd5bd2a, 3d9ff48)
  • the filename option can now be a function (c5beb4b)
  • add support for 'auto' public paths inside templates (a059fcf, b09b439)
  • use defer as default script loading mechanism (35b6b87)
  • allow to set publicPath to an empty string '' (5ea7de4)
  • improve typings (197ddd8)
  • provide public path to the alterAssetTagGroups hook (1b54dfb)
  • provide public path to the alterAssetTags hook (b754626)
  • use thisCompilation in child compiler for faster builds (1d59e9a)
  • export new major in static property (8b692bd)
  • reduce dependencies (8c28aaa, 56e633f)

Bug Fixes

  • emit files on every build to work properly with plugins like the clean-webpack-plugin (6b3d087)
  • generate html files even if no webpack entry exists (2693dfa)
  • keep binary format when adding assets (7e2b208), closes #1537

4.5.2 (2021-02-18)

Bug Fixes

  • more robust variable value extraction to add support for webpack >= 5.22.0 (1aabaf9)

4.5.1 (2021-01-03)

Bug Fixes

  • inject javascripts in the <head> tag for inject:true and scriptLoading:'defer' (4f7064e)

4.5.0 (2020-09-21)

Features

  • Add publicPath option to overrule the default path generation (#1516) (19b5122)
  • update webpack dependency range to allow installing webpack 5 beta (f3ccdd5), closes #1504

4.4.1 (2020-08-30)

Bug Fixes

4.4.0 (2020-08-30)

Bug Fixes

Features

  • added v5 compilation support and deleted depreciation warnings (4ae7be8), closes #1454

4.3.0 (2020-04-30)

Features

  • Allow to use console.log inside templates (c3f2fdc)

4.2.2 (2020-04-30)

Bug Fixes

  • Prevent "cannot read property info of undefined" when reading meta information from assets (253ce30)
  • use modern icon tag rel attribute for favicons (c40dd85)

4.2.1 (2020-04-28)

Bug Fixes

  • don't add dependencies twice to the webpack 5 watcher api (ceafe14)
  • prevent scripts marked as hotModuleReplacement from being added to the html file (119252a)

4.2.0 (2020-04-09)

Features

4.1.0 (2020-04-09)

Features

  • Add webpack 5 support (39c38a4)
  • Allow webpack 5 as peer dependency (9c571e2)

4.0.4 (2020-04-01)

Bug Fixes

4.0.3 (2020-03-28)

Bug Fixes

  • add webpack, tapable and html-minifier-terser as dependencies because of types.d.ts (238da81)

4.0.2 (2020-03-26)

Bug Fixes

  • don't remove trailing slashes from self closing tags by default (2281e4b)

4.0.1 (2020-03-23)

Bug Fixes

  • update typedefs to match with html-minifier-terser (2698c7e)

4.0.0 (2020-03-23)

The summary can be found in the release blog post.

Bug Fixes

  • Add dependencies from the child compilation to the main compilation (27c3e72)
  • Add typing for assets(Close jantimon#1243) (9fef060)
  • allow contenthash along with templatehash (049d4d3), closes #1033
  • Catch and ignore pretty-error errors (2056139), closes #921
  • Drop @types/webpack dependency (d4eb1c7)
  • Ignore foreign child compilers (1422664)
  • Improve perfomance for appcache files (b94e043)
  • load script files before style files files in defer script loading mode (97f9fb9)
  • Prevent chunks from beeing added multiple times (d65b37d)
  • Prevent lodash from being inlined to work around a babel-loader incompatibility (7f21910), closes #1223
  • Remove compilation.getStats() call for performance reasons (7005a55)
  • remove useless links for options (#1153) (267e0e0)
  • Update references to html-minifier (24bf1b5), closes #1311
  • typings.d.ts: added apply method type to HtmlWwbpackPlugin class definitoin (8b7255f), closes jantimon#1244
  • rename contenthash to templatehash (4c11c5d)
  • Repair typings (#1166) (f4cb241)
  • small type. minifcation instead of minification (#1154) (56037a6)
  • Use src/index.ejs by default if present (#1167) (c27e5e4)
  • chunksorter: Don't sort chunks by default (22fb03f)
  • loader: switch to loaderUtils.getOptions (a0a0f0d)
  • README: adds a link to template option documentation (f40aeae)
  • tests: Upgrade webpack-recompilation-simulator (dfe1d10)
  • Update lodash to 4.17.10 (cc3bf49)

Code Refactoring

  • Change the structure of the internal assets object (37db086)
  • Changed hook names and arguments - the hook order is 'beforeAssetTagGeneration', 'alterAssetTags', 'alterAssetTagGroups', 'afterTemplateExecution', 'beforeEmit', 'afterEmit' (14b4456)
  • Use Webpack 4 APIs (47efdea)

Features

  • add .toString implementation to htmlTags to allow easier rendering (34d8aa5)
  • Add default viewport meta tag for default template (302e39e), closes #897 #978
  • Add defer script loading (de315eb)
  • Add support for relative publicPath (dbbdd81)
  • Add support for <base> tag (#1160) (c5d4b86)
  • Add support for minifying inline ES6 inside html templates (c66766c), closes #1262
  • Add support for the [contenthash] placeholder inside htm file names (ae8233a)
  • Add typings to package.json (a524e8f), closes #1132
  • Allow to return async template parameters (99f9362)
  • drop workaround for "Uncaught TypeError: webpack_require(...) is not a function" to be compatible with webpack 5 (15ad0d2)
  • Export major version of this plugin (6ae6f48)
  • merge templateParameters with default template parameters (1d66e53)
  • Provide a verbose error message if html minification failed (7df269f)
  • compiler: Add file dependencies (bbc07a3)
  • compiler: Use a single compiler for multiple plugin instances (f29ae88)
  • compiler: Use timestamps to verify cache validity (0ebcd17)
  • Remove selfClosingTag (5d3d8e4)
  • Remove type="text/javascript" from injected script tags (b46bf67)
  • Replace jade with pug in examples (d7ec407)
  • Switch from jasmine to jest (ae1f435)
  • hooks: Add a helper for easier hook access (b6dec4b)
  • hooks: Provide static getHook method for access to all html-webpack-plugin hooks (#995) (82b34a1)
  • Simplify <meta> element and charset attribute (55313be)
  • support ES6 template string in default loader (d6b65dd), closes #950
  • Use jsdoc for static typing (a6b8d2d)
  • Use webpack 4 entries api to extract asset information (342867e)
  • html-tags: Add a helper to create html-tags (ee6a165)

BREAKING CHANGES

  • defaults: Use src/index.ejs if no template option is set.
  • defaults: The default template has now a predefined viewport meta tag
  • defaults: The default meta utf-8 declaration was changed to <meta charset="utf-8"/>
  • hooks: Renamed beforeHtmlGeneration hook to beforeAssetTagGeneration
  • hooks: Renamed beforeHtmlProcessing hook to alterAssetTags
  • hooks: Renamed afterHtmlProcessing hook to beforeEmit
  • hooks: The html-webpack-plugin doesn't add its hooks to the compilation object anymore
  • The assets object which is used for the template parameters and inside hooks was changed. The chunks property was removed and the js and css property was converted from a string into an object { entryName: string, path: string}
  • The mimetype information "text/javascript" is removed from all generated script tags
  • Remove selfClosingTag attribute
  • Template strings inside templates are now disabled by default
  • Dropped support for Webpack 1 - 3
  • Template variable webpack was removed
  • chunksorter: Chunks aren't sorted anymore by default

3.2.0 (2018-04-03)

Bug Fixes

  • loader: Allow to add new template parameters (f7eac19), closes #915
  • loader: Use lodash inside the loader directly (7b4eb7f), closes #786

Features

3.1.0 (2018-03-22)

Features

  • Allow to overwrite the templateParameter #830 (c5e32d3)

3.0.8 (2018-03-22)

Bug Fixes

  • compiler: Fallback to 3.0.7 because of #900 (05ee29b)

3.0.7 (2018-03-19)

Bug Fixes

3.0.6 (2018-03-06)

Bug Fixes

3.0.5 (2018-03-06)

Bug Fixes

  • entries: do not ignore JS if there is also CSS (020b714)
  • entries: Don't add css entries twice (0348d6b)
  • hooks: Remove deprecated tapable calls #879 (2288f20)

3.0.4 (2018-03-01)

Bug Fixes

  • entries: Don't add css entries twice (e890f23)

3.0.3 (2018-03-01)

Refactor

  • performance: Reduce the amount of chunk information gathered based on #825 (06c59a7)

3.0.2 (2018-03-01)

Bug Fixes

  • query-loader: In case no query is provided, return an empty object. This fixes #727 (7587754)

3.0.1 (2018-03-01)

Bug Fixes

  • package: Remove the extract-text-webpack-plugin peer dependency (57411a9)

3.0.0 (2018-28-02)

Features

  • Add support for the new webpack tapable to be compatible with webpack 4.x
  • Remove bluebird dependency

BREAKING CHANGES

  • Similar to webpack 4.x the support for node versions older than 6 are no longer supported

2.30.1

  • Revert part the performance optimization (#723) because of #753.

2.30.0

  • Add manual sort
  • Performance improvements (#723)

2.29.0

  • Add support for Webpack 3

2.28.0

  • Backport 3.x void tag for plugin authors

2.27.1

  • Revert 2.25.0 loader resolving

2.27.0

  • Fix a chunksorter webpack 2 issue (#569)
  • Fix template path resolving (#542)

2.26.0

  • Allow plugins to add attributes without values to the <script> and <link> tags

2.25.0

  • Clearer loader output
  • Add basic support for webpack 2

2.24.1

  • Hide event deprecated warning of 'applyPluginsAsyncWaterfall' for html-webpack-plugin-after-emit and improve the warning message.

2.24.0

  • Update dependencies
  • Add deprecate warning for plugins not returning a result
  • Add [path] for favicons

2.23.0

  • Update dependencies
  • Stop automated tests for webpack 2 beta because of #401

2.22.0

  • Update dependencies

2.21.1

  • Better error handling (#354)

2.21.0

  • Add html-webpack-plugin-alter-asset-tags event to allow plugins to adjust the script/link tags

2.20.0

  • Exclude chunks works now even if combined with dependency sort

2.19.0

  • Add html-webpack-plugin-alter-chunks event for custom chunk sorting and interpolation

2.18.0

  • Updated all dependencies

2.17.0

  • Add type attribute to script element to prevent issues in Safari 9.1.1

2.16.2

  • Fix bug introduced by 2.16.2. Fixes #315

2.16.1

  • Fix hot module replacement for webpack 2.x

2.16.0

  • Add support for dynamic filenames like index[hash].html

2.15.0

  • Add full unit test coverage for the webpack 2 beta version
  • For webpack 2 the default sort will be 'dependency' instead of 'id'
  • Upgrade dependencies

2.14.0

  • Export publicPath to the template
  • Add example for inlining css and js

2.13.0

  • Add support for absolute output file names
  • Add support for relative file names outside the output path

2.12.0

  • Basic Webpack 2.x support #225

2.11.0

  • Add xhtml option which is turned of by default. When activated it will inject self closed <link href=".." /> tags instead of unclosed <link href=".."> tags. (#255)
  • Add support for webpack placeholders inside the public path e.g. '/dist/[hash]/'. (#249)

2.10.0

  • Add hash field to the chunk object
  • Add compilation field to the templateParam object (#237)
  • Add html-webpack-plugin-before-html-generation event
  • Improve error messages

2.9.0

2.8.2

  • Support relative URLs on Windows (#205)

2.8.1

  • Caching improvements (#204)

2.8.0

  • Add dependency mode for chunksSortMode to sort chunks based on their dependencies with each other

2.7.2

  • Add support for require in js templates

2.7.1

  • Refactoring
  • Fix relative windows path

2.6.5

  • Minor refactoring

2.6.4

  • Fix for "Uncaught TypeError: __webpack_require__(...) is not a function"
  • Fix incomplete cache modules causing "HtmlWebpackPlugin Error: No source available"
  • Fix some issues on Windows

2.6.3

  • Prevent parsing the base template with the html-loader

2.6.2

  • Fix lodash resolve error (#172)

2.6.1

  • Fix missing module (#164)

2.6.0

  • Move compiler to its own file
  • Improve error messages
  • Fix global HTML_WEBPACK_PLUGIN variable

2.5.0

  • Support lodash template's HTML "escape" delimiter (<%- %>)
  • Fix bluebird warning (#130)
  • Fix an issue where incomplete cache modules were used

2.4.0

  • Don't recompile if the assets didn't change

2.3.0

  • Add events html-webpack-plugin-before-html-processing, html-webpack-plugin-after-html-processing, html-webpack-plugin-after-emit to allow other plugins to alter the html this plugin executes

2.2.0

  • Inject css and js even if the html file is incomplete (#135)
  • Update dependencies

2.1.0

  • Synchronize with the stable @1 version

2.0.4

  • Fix minify option
  • Fix missing hash interpolation in publicPath

2.0.3

  • Add support for webpack.BannerPlugin

2.0.2

  • Add support for loaders in templates (#41)
  • Remove templateContent option from configuration
  • Better error messages
  • Update dependencies

1.7.0

  • Add chunksSortMode option to configuration to control how chunks should be sorted before they are included to the html
  • Don't insert async chunks into html (#95)
  • Update dependencies

1.6.2

  • Fix paths on Windows
  • Fix missing hash interpolation in publicPath
  • Allow only false or object in minify configuration option

1.6.1

  • Add size field to the chunk object
  • Fix stylesheet <link>s being discarded when used with "inject: 'head'"
  • Update dependencies

1.6.0

  • Support placing templates in subfolders
  • Don't include chunks with undefined name (#60)
  • Don't include async chunks

1.5.2

  • Update dependencies (lodash)

1.5.1

  • Fix error when manifest is specified (#56)

1.5.0

  • Allow to inject javascript files into the head of the html page
  • Fix error reporting

1.4.0

  • Add favicon.ico option
  • Add html minifcation

1.2.0

  • Set charset using HTML5 meta attribute
  • Reload upon change when using webpack watch mode
  • Generate manifest attribute when using appcache-webpack-plugin
  • Optionally add webpack hash as a query string to resources included in the HTML (hash: true) for cache busting
  • CSS files generated using webpack (for example, by using the extract-text-webpack-plugin) are now automatically included into the generated HTML
  • More detailed information about the files generated by webpack is now available to templates in the o.htmlWebpackPlugin.files attribute. See readme for more details. This new attribute deprecates the old o.htmlWebpackPlugin.assets attribute.
  • The templateContent option can now be a function that returns the template string to use
  • Expose webpack configuration to templates (o.webpackConfig)
  • Sort chunks to honour dependencies between them (useful for use with CommonsChunkPlugin).