{"id":21937426,"url":"https://github.com/packingjs/packing-html-webpack-plugin","last_synced_at":"2026-04-15T18:04:10.701Z","repository":{"id":57317859,"uuid":"62633076","full_name":"packingjs/packing-html-webpack-plugin","owner":"packingjs","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-08T04:39:56.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-20T13:08:24.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/packingjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-05T11:56:23.000Z","updated_at":"2017-06-08T04:16:48.000Z","dependencies_parsed_at":"2022-08-25T21:12:16.871Z","dependency_job_id":null,"html_url":"https://github.com/packingjs/packing-html-webpack-plugin","commit_stats":null,"previous_names":["zhongzhi107/packing-html-webpack-plugin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/packingjs/packing-html-webpack-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-html-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-html-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-html-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-html-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/packingjs","download_url":"https://codeload.github.com/packingjs/packing-html-webpack-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/packingjs%2Fpacking-html-webpack-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31853280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T01:19:44.662Z","updated_at":"2026-04-15T18:04:10.663Z","avatar_url":"https://github.com/packingjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"HTML Webpack Plugin\n===================\n[![npm version](https://badge.fury.io/js/html-webpack-plugin.svg)](http://badge.fury.io/js/html-webpack-plugin) [![Dependency Status](https://david-dm.org/ampedandwired/html-webpack-plugin.svg)](https://david-dm.org/ampedandwired/html-webpack-plugin) [![Build status](https://travis-ci.org/ampedandwired/html-webpack-plugin.svg)](https://travis-ci.org/ampedandwired/html-webpack-plugin) [![Windows build status](https://ci.appveyor.com/api/projects/status/github/ampedandwired/html-webpack-plugin?svg=true\u0026branch=master)](https://ci.appveyor.com/project/jantimon/html-webpack-plugin) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard) [![bitHound Dependencies](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/badges/dependencies.svg)](https://www.bithound.io/github/ampedandwired/html-webpack-plugin/master/dependencies/npm) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)]()\n\n[![NPM](https://nodei.co/npm/html-webpack-plugin.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/html-webpack-plugin/)\n\nThis is a [webpack](http://webpack.github.io/) plugin that simplifies creation of HTML files to serve your\nwebpack bundles. This is especially useful for webpack bundles that include\na hash in the filename which changes every compilation. You can either let the plugin generate an HTML file for you, supply\nyour own template using lodash templates or use your own loader.\n\nMaintainer: Jan Nicklas [@jantimon](https://twitter.com/jantimon)\n\nInstallation\n------------\nInstall the plugin with npm:\n```shell\n$ npm install html-webpack-plugin --save-dev\n```\n\nMigration guide from 1.x\n------------------------\n\n[Changelog](https://github.com/ampedandwired/html-webpack-plugin/blob/master/CHANGELOG.md)\n\nIf you used the 1.x version please take a look at the [migration guide](https://github.com/ampedandwired/html-webpack-plugin/blob/master/migration.md)\n\n\nBasic Usage\n-----------\n\nThe plugin will generate an HTML5 file for you that includes all your webpack\nbundles in the body using `script` tags. Just add the plugin to your webpack\nconfig as follows:\n\n```javascript\nvar HtmlWebpackPlugin = require('html-webpack-plugin');\nvar webpackConfig = {\n  entry: 'index.js',\n  output: {\n    path: 'dist',\n    filename: 'index_bundle.js'\n  },\n  plugins: [new HtmlWebpackPlugin()]\n};\n```\n\nThis will generate a file `dist/index.html` containing the following:\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eWebpack App\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cscript src=\"index_bundle.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nIf you have multiple webpack entry points, they will all be included with `script`\ntags in the generated HTML.\n\nIf you have any css assets in webpack's output (for example, css extracted\nwith the [ExtractTextPlugin](https://github.com/webpack/extract-text-webpack-plugin))\nthen these will be included with `\u003clink\u003e` tags in the HTML head.\n\nConfiguration\n-------------\nYou can pass a hash of configuration options to `HtmlWebpackPlugin`.\nAllowed values are as follows:\n\n- `title`: The title to use for the generated HTML document.\n- `filename`: The file to write the HTML to. Defaults to `index.html`.\n   You can specify a subdirectory here too (eg: `assets/admin.html`).\n- `template`: Webpack require path to the template. Please see the [docs](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md) for details. \n- `inject`: `true | 'head' | 'body' | false` Inject all assets into the given `template` or `templateContent` - When passing `true` or `'body'` all javascript resources will be placed at the bottom of the body element. `'head'` will place the scripts in the head element.\n- `favicon`: Adds the given favicon path to the output html.\n- `minify`: `{...} | false` Pass a [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) options object to minify the output.\n- `hash`: `true | false` if `true` then append a unique webpack compilation hash to all\n  included scripts and css files. This is useful for cache busting.\n- `cache`: `true | false` if `true` (default) try to emit the file only if it was changed.\n- `showErrors`: `true | false` if `true` (default) errors details will be written into the html page.\n- `chunks`: Allows you to add only some chunks (e.g. only the unit-test chunk)\n- `chunksSortMode`: Allows to control how chunks should be sorted before they are included to the html. Allowed values: 'none' | 'auto' | 'dependency' | {function} - default: 'auto'\n- `excludeChunks`: Allows you to skip some chunks (e.g. don't add the unit-test chunk)\n- `xhtml`: `true | false` If `true` render the `link` tags as self-closing, XHTML compliant. Default is `false`\n\nHere's an example webpack config illustrating how to use these options:\n```javascript\n{\n  entry: 'index.js',\n  output: {\n    path: 'dist',\n    filename: 'index_bundle.js'\n  },\n  plugins: [\n    new HtmlWebpackPlugin({\n      title: 'My App',\n      filename: 'assets/admin.html'\n    })\n  ]\n}\n```\n\nFAQ\n----\n\n* [Why is my html minified?](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)\n* [Why is my `\u003c% ... %\u003e` template not working?](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)\n* [How can I use handlebars/pug/ejs as template engine](https://github.com/ampedandwired/html-webpack-plugin/blob/master/docs/template-option.md)\n\nGenerating Multiple HTML Files\n------------------------------\nTo generate more than one HTML file, declare the plugin more than\nonce in your plugins array:\n```javascript\n{\n  entry: 'index.js',\n  output: {\n    path: 'dist',\n    filename: 'index_bundle.js'\n  },\n  plugins: [\n    new HtmlWebpackPlugin(), // Generates default index.html\n    new HtmlWebpackPlugin({  // Also generate a test.html\n      filename: 'test.html',\n      template: 'src/assets/test.html'\n    })\n  ]\n}\n```\n\nWriting Your Own Templates\n--------------------------\nIf the default generated HTML doesn't meet your needs you can supply\nyour own template. The easiest way is to use the `inject` option and pass a custom html file.\nThe html-webpack-plugin will automatically inject all necessary css, js, manifest\nand favicon files into the markup.\n\n```javascript\nplugins: [\n  new HtmlWebpackPlugin({\n    title: 'Custom template',\n    template: 'my-index.ejs', // Load a custom template (ejs by default see the FAQ for details)\n  })\n]\n```\n\n`my-index.ejs`:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\"/\u003e\n    \u003ctitle\u003e\u003c%= htmlWebpackPlugin.options.title %\u003e\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nIf you already have a template loader, you can use it to parse the template.\nPlease note that this will also happen if you specifiy the html-loader and use `.html` file as template.\n\n```javascript\nmodule: {\n  loaders: [\n    { test: /\\.hbs$/, loader: \"handlebars\" }\n  ]\n},\nplugins: [\n  new HtmlWebpackPlugin({\n    title: 'Custom template using Handlebars',\n    template: 'my-index.hbs'\n  })\n]\n```\n\nYou can use the lodash syntax out of the box.\nIf the `inject` feature doesn't fit your needs and you want full control over the asset placement use the [default template](https://github.com/jaketrent/html-webpack-template/blob/86f285d5c790a6c15263f5cc50fd666d51f974fd/index.html) of the [html-webpack-template project](https://github.com/jaketrent/html-webpack-template) as a starting point for writing your own.\n\nThe following variables are available in the template:\n- `htmlWebpackPlugin`: data specific to this plugin\n  - `htmlWebpackPlugin.files`: a massaged representation of the\n    `assetsByChunkName` attribute of webpack's [stats](https://github.com/webpack/docs/wiki/node.js-api#stats)\n    object. It contains a mapping from entry point name to the bundle filename, eg:\n    ```json\n    \"htmlWebpackPlugin\": {\n      \"files\": {\n        \"css\": [ \"main.css\" ],\n        \"js\": [ \"assets/head_bundle.js\", \"assets/main_bundle.js\"],\n        \"chunks\": {\n          \"head\": {\n            \"entry\": \"assets/head_bundle.js\",\n            \"css\": [ \"main.css\" ]\n          },\n          \"main\": {\n            \"entry\": \"assets/main_bundle.js\",\n            \"css\": []\n          },\n        }\n      }\n    }\n    ```\n    If you've set a publicPath in your webpack config this will be reflected\n    correctly in this assets hash.\n\n  - `htmlWebpackPlugin.options`: the options hash that was passed to\n     the plugin. In addition to the options actually used by this plugin,\n     you can use this hash to pass arbitrary data through to your template.\n\n- `webpack`: the webpack [stats](https://github.com/webpack/docs/wiki/node.js-api#stats)\n  object. Note that this is the stats object as it was at the time the HTML template\n  was emitted and as such may not have the full set of stats that are available\n  after the wepback run is complete.\n\n- `webpackConfig`: the webpack configuration that was used for this compilation. This\n  can be used, for example, to get the `publicPath` (`webpackConfig.output.publicPath`).\n\n\nFiltering chunks\n----------------\n\nTo include only certain chunks you can limit the chunks being used:\n\n```javascript\nplugins: [\n  new HtmlWebpackPlugin({\n    chunks: ['app']\n  })\n]\n```\n\nIt is also possible to exclude certain chunks by setting the `excludeChunks` option:\n\n```javascript\nplugins: [\n  new HtmlWebpackPlugin({\n    excludeChunks: ['dev-helper']\n  })\n]\n```\n\nEvents\n------\n\nTo allow other [plugins](https://github.com/webpack/docs/wiki/plugins) to alter the html this plugin executes the following events:\n\nAsync:\n\n * `html-webpack-plugin-before-html-generation`\n * `html-webpack-plugin-before-html-processing`\n * `html-webpack-plugin-alter-asset-tags`\n * `html-webpack-plugin-after-html-processing`\n * `html-webpack-plugin-after-emit`\n\nSync:\n\n * `html-webpack-plugin-alter-chunks`\n\nExample implementation: [html-webpack-harddisk-plugin](https://github.com/jantimon/html-webpack-harddisk-plugin)\n\nUsage:\n\n```javascript\n// MyPlugin.js\n\nfunction MyPlugin(options) {\n  // Configure your plugin with options...\n}\n\nMyPlugin.prototype.apply = function(compiler) {\n  // ...\n  compiler.plugin('compilation', function(compilation) {\n    console.log('The compiler is starting a new compilation...');\n\n    compilation.plugin('html-webpack-plugin-before-html-processing', function(htmlPluginData, callback) {\n      htmlPluginData.html += 'The magic footer';\n      callback(null, htmlPluginData);\n    });\n  });\n\n};\n\nmodule.exports = MyPlugin;\n```\nThen in `webpack.config.js`\n\n```javascript\nplugins: [\n  new MyPlugin({options: ''})\n]\n```\n\nNote that the callback must be passed the htmlPluginData in order to pass this onto any other plugins listening on the same 'html-webpack-plugin-before-html-processing' event.\n\n\n# Contribution\n\nYou're free to contribute to this project by submitting [issues](https://github.com/ampedandwired/html-webpack-plugin/issues) and/or [pull requests](https://github.com/ampedandwired/html-webpack-plugin/pulls). This project is test-driven, so keep in mind that every change and new feature should be covered by tests.\nThis project uses the [semistandard code style](https://github.com/Flet/semistandard).\n\n# License\n\nThis project is licensed under [MIT](https://github.com/ampedandwired/html-webpack-plugin/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpackingjs%2Fpacking-html-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpackingjs%2Fpacking-html-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpackingjs%2Fpacking-html-webpack-plugin/lists"}