rollup-plugin-hash

raw JSON →
1.3.0 verified Mon Apr 27 auth: no javascript maintenance

Rollup plugin to append content hashes to bundle filenames using a [hash] placeholder pattern, enabling long-term caching. Current stable version is 1.3.0, last updated in 2019. It supports configurable hash algorithms (md5, sha1, sha256, sha512), truncation via [hash:N], optional manifest generation mapping original to hashed filenames, and a replace option to overwrite the original output. Release cadence is low; package is in maintenance mode. Differentiators include simplicity and explicit manifest support, though it is not actively developed and may lack native Rollup v2+ plugin API compliance.

error Error: rollup-plugin-hash: dest option must contain [hash] placeholder
cause Missing [hash] in dest string.
fix
Add [hash] to dest, e.g., dest: 'bundle.[hash].js'
error TypeError: hash is not a function
cause Using named import instead of default import.
fix
Use import hash from 'rollup-plugin-hash' (no curly braces).
error Error: Cannot find module 'rollup-plugin-hash'
cause Package not installed or wrong Node.js version (requires Node >=8).
fix
Run npm install --save-dev rollup-plugin-hash
breaking The plugin does not support Rollup's output.file option directly; it renames after write, which may conflict with other plugins.
fix Set output.file to the non-hashed name and use plugin's dest option.
deprecated Package is no longer actively maintained; last release 2019. No updates for Rollup v3+ compatibility.
fix Consider alternatives like rollup-plugin-output-manifest or manual hash generation.
gotcha Plugin uses writeBundle hook; it may fail if Rollup generates multiple outputs (e.g., multiple formats).
fix Use a single output; for multiple outputs, consider using generateBundle hook plugins.
gotcha The [hash] placeholder must be in dest option; omitting it throws an error.
fix Always include '[hash]' in dest template.
npm install rollup-plugin-hash
yarn add rollup-plugin-hash
pnpm add rollup-plugin-hash

Basic Rollup build with rollup-plugin-hash: generates hashed output filename and writes a manifest file.

import { rollup } from 'rollup';
import hash from 'rollup-plugin-hash';

async function build() {
  const bundle = await rollup({
    input: 'src/index.js',
    plugins: [
      hash({
        dest: 'dist/bundle.[hash:8].js',
        manifest: 'dist/manifest.json'
      })
    ]
  });
  await bundle.write({ format: 'iife', file: 'dist/bundle.js' });
}
build().catch(console.error);