Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hash-content-html-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-content-html-webpack-plugin - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

2

package.json
{
"name": "hash-content-html-webpack-plugin",
"version": "1.1.0",
"version": "1.1.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "src/index.js",

# hash-content-html-webpack-plugin
Generate md5 hash for html file (e.g. `index.f8704d178ff376c380a6.html`),
based on file's content and working with [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin).
# Why use hash-content-html-webpack-plugin?
index.html
```html
<!doctype html>
<head><link href="/app/css/index.8a09fef2bfaf1c05ca22.css" rel="stylesheet"></head>
<body>
<script type="text/javascript" src="/app/js/vendor.d5474870259fc6bd8afb.js"></script>
<script type="text/javascript" src="/app/js/index.40555284b534ede23047.js"></script>
</body></html>
```
webpack.config.js
```js
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
...
plugins: [
...
new HtmlWebpackPlugin({
filename: 'index.[hash].html'
}),
]
}
// output: index.c5474870259fc6bd8afd.html
```
Once `css` and `js` are modified, their hash will change(e.g. `/app/css/index.8a09fef2bfaf1c05ca22.css` changes to `/app/css/index.375969b84db8a0c16a1d.css `), so html's content will change,but html's hash will not change by using `[hash]` `[chunkhash]`, the output is still `index.c5474870259fc6bd8afd.html`。So if you want to change html's hash when html's content changes, you should use `[contenthash]` provided by `hash-content-html-webpack-plugin`.
# Install
```sh
npm install hash-content-html-webpack-plugin --save-dev
```
# Usage
webpack.config.js
```js
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HashContentHtmlWebpackPlugin = require('hash-content-html-webpack-plugin')
module.exports = {
...
plugins: [
...
new HtmlWebpackPlugin({
filename: 'index.[contenthash].html'
}),
new HashContentHtmlWebpackPlugin()
]
}
// output: index.f8704d178ff376c380a6.html
```
# License
MIT

@@ -9,3 +9,3 @@ const hasha = require('hasha')

'html-webpack-plugin-after-emit',
({ outputName, html }) => {
({ outputName, html }, callback) => {
const chunk = compilation.assets[outputName]

@@ -18,2 +18,3 @@ const hash = hasha(html.source(), {

delete compilation.assets[outputName]
callback && callback()
}

@@ -20,0 +21,0 @@ )

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc