webpack-chunk-hash

raw JSON →
0.6.0 verified Sat Apr 25 auth: no javascript maintenance

Webpack plugin that replaces standard chunk hashing with a custom MD5 hash, without sorting chunks (unobtrusive) and using Node's native crypto module for performance. Current stable version is 0.6.0, which supports Webpack 4 while maintaining backward compatibility with Webpack 3. It is a clone of webpack-md5-hash but avoids chunk sorting and uses native crypto. The plugin offers options for algorithm, digest, and additional hash content. Release cadence is low; the plugin is stable but not actively developed.

error TypeError: WebpackChunkHash is not a constructor
cause Using a named import (import { WebpackChunkHash }) when the package exports via module.exports.
fix
Use default import: const WebpackChunkHash = require('webpack-chunk-hash');
error Cannot find module 'webpack-chunk-hash'
cause Package not installed or not in node_modules.
fix
Run: npm install --save-dev webpack-chunk-hash
deprecated Webpack 4 integrated improved hashing natively; this plugin may be unnecessary.
fix Consider removing the plugin and relying on Webpack 4's built-in hashing or upgrading to Webpack 5 which uses content hash.
breaking Webpack 5 dropped support for [chunkhash] in favor of [contenthash]; this plugin may not work with Webpack 5.
fix Use [contenthash] instead of [chunkhash] and replace this plugin with Webpack 5's built-in deterministic hashing.
gotcha The plugin does not sort chunks before hashing; this can lead to inconsistent hashes across builds if chunk order varies.
fix Ensure chunk order is deterministic or use a plugin that sorts chunks (e.g., webpack-md5-hash).
gotcha Only CommonJS require is supported; ESM imports may fail if the bundler does not handle CJS interop.
fix Use require() or configure your bundler for CJS interop.
npm install webpack-chunk-hash
yarn add webpack-chunk-hash
pnpm add webpack-chunk-hash

Replaces Webpack's default chunk hashing with MD5 using the plugin. Configures output filenames with [chunkhash] and applies the plugin.

// webpack.config.js
const WebpackChunkHash = require('webpack-chunk-hash');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: '[name].[chunkhash].js',
    chunkFilename: '[name].[chunkhash].js',
  },
  plugins: [
    new WebpackChunkHash({ algorithm: 'md5', digest: 'hex' })
  ]
};