Gathering detailed insights and metrics for webpack-plugin-hash-output
Gathering detailed insights and metrics for webpack-plugin-hash-output
Gathering detailed insights and metrics for webpack-plugin-hash-output
Gathering detailed insights and metrics for webpack-plugin-hash-output
webpack-plugin-hash-output-v3
Plugin for Webpack3 that uses the final output to compute the hash of an asset
@sewing-kit/webpack-plugin-hash-output
TODO finish moving over and modernizing from https://github.com/Shopify/webpack-plugin-hash-output
webpack-plugin-hash-output-mini-css
Plugin for Webpack that uses the final output to compute the hash of an asset
@shopify/webpack-plugin-hash-output
Temporary fork of the plugin for Webpack that uses the final output to compute the hash of an asset
npm install webpack-plugin-hash-output
Typescript
Module System
80.5
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
JavaScript (99.86%)
CSS (0.14%)
Total Downloads
7,602,415
Last Day
309
Last Week
3,759
Last Month
23,033
Last Year
379,260
128 Stars
94 Commits
29 Forks
7 Watching
18 Branches
6 Contributors
Latest Version
3.2.1
Package Id
webpack-plugin-hash-output@3.2.1
Size
7.54 kB
Publised On
22 Jan 2019
Cumulative downloads
Total Downloads
Last day
-71.7%
309
Compared to previous day
Last week
-24.2%
3,759
Compared to previous week
Last month
-24.6%
23,033
Compared to previous month
Last year
-66.8%
379,260
Compared to previous year
Plugin to replace webpack chunkhash with an md5 hash of the final file conent.
With npm
npm install webpack-plugin-hash-output --save-dev
With yarn
yarn add webpack-plugin-hash-output --dev
There are other webpack plugins for hashing out there. But when they run, they don't "see" the final form of the code, because they run
before plugins like webpack.optimize.UglifyJsPlugin
. In other words, if you change webpack.optimize.UglifyJsPlugin
config, your
hashes won't change, creating potential conflicts with cached resources.
The main difference is that webpack-plugin-hash-output
runs in the last compilation step. So any change in webpack or any other plugin
that actually changes the output, will be "seen" by this plugin, and therefore that change will be reflected in the hash.
It will generate files like entry.<hash>.js
, where <hash>
is always a hash of the content (well, a subset of). Example:
$ md5 entry.32f1718dd08eccda2791.js
MD5 (entry.32f1718dd08eccda2791.js) = 32f1718dd08eccda2791ff7ed466bd98
All other assets (common files, manifest files, HTML output...) will use the new md5 hash to reference the asset.
Requires webpack >=4
Just add this plugin as usual.
1// webpack.config.js 2const HashOutput = require('webpack-plugin-hash-output'); 3 4module.exports = { 5 // ... 6 output: { 7 //... 8 filename: '[name].[chunkhash].js', 9 }, 10 plugins: [ 11 new HashOutput(options) 12 ] 13};
This plugin partially supports sourcemaps. When a chunk hash is recomputed, it will update the name of the chunk in the chunks's sourcemap, but it won't recompute the name of the hash file. This has the side effect that the name of the sourcemap will differ from the name of the chunk. Example:
Before:
1// app.<oldhash>.js 2 3// ...code... 4//# sourceMappingURL=entry.<oldhash>.js.map
1// app.<oldhash>.js.map 2 3// ... 4"file":"app.<oldhash>.js" 5// ...
After:
1// app.<newhash>.js 2 3// ...code... 4//# sourceMappingURL=entry.<oldhash>.js.map
1// app.<oldhash>.js.map 2 3// ... 4"file":"app.<newhash>.js" 5// ...
We can't fully support sourcemaps (i.e. recomute sourcemap hash) because the circular reference: we can't compute sourcemap hash without computing the file hash first, and we can't compute the file hash without the sourcemap hash.
Because this plugin modifies the name of the assets, it break other plugins that also operate on the name of the assets
if the order of the plugins is not correct. For plugin-webpack-hash-output
to work, it has to be the first plugin to
run in the emit
phase. Inside the same phase, the order of the plugins is determined by the order in which they appear
in webpack's config option plugins
.
A specific example of this is html-webpack-plugin: plugin-webpack-hash-output
must be listed before html-webpack-plugin
. Example:
1plugins: [ 2 new HashOutput(...), 3 new HtmlWebpackPlugin(...), 4]
When the webpack compilation starts, this plugin will check if there are other plugins that might conflict with the output and display a warning. It is recommended you fix the order of the plugins unless you really know what you are doing:
[WARNING] There are other plugins configured that might interfere with webpack-plugin-hash-output.
For this plugin to work correctly, it should be the first plugin in the "emit" phase. Please
be sure that the rest of the plugins run after webpack-plugin-hash-output (ensure they are listed
after webpack-plugin-hash-output in the 'plugins' option in your webpack config).
Plugins that could interfere with webpack-plugin-hash-output:
* HtmlWebpackPlugin
Note: Use Webpack's own hash output options to configure hash function and length.
options.validateOutput
boolean
, defaults to false
.
After webpack has compiled and generated all the assets, checks that the hash of the content is included in the file. If it is not, it will throw an error and the webpack process will fail.
options.validateOutputRegex
regex
, defaults to /^.*$/
When validating the output (see options.validateOutput
), only evaluate hashes for files matching this regexp.
Useful for skipping source maps or other output. Example:
1module.exports = { 2 entry: { 3 main: './src/app.js', 4 }, 5 output: { 6 filename: 'assets/[name].[chunkhash].js', 7 }, 8 plugins: [ 9 new HashOutput({ 10 validateOutput: true, 11 // Check that md5(assets/main.<hash>.js) === <hash>, but doesn't check fragments/app.html 12 validateOutputRegex: /^assets\/.*\.js$/, 13 }), 14 new HtmlWebpackPlugin({ 15 filename: 'fragments/app.html', 16 chunks: ['main'], 17 }), 18 ] 19};
Tests can be run by:
yarn test
After running the tests, you might want to run yarn run clean
to clean up temp files generated by the tests.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 4/25 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More