npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

build-hasher

v0.0.2

Published

Library for hashing static assets and updating file references. Perfect for build tools, bundlers, and asset management.

Readme

build-hasher

Node.js library for hashing static assets and updating file references.

npm version Node.js version License: MIT

Features

  • ES Modules & CommonJS support
  • TypeScript definitions included
  • Build tool integration
  • Flexible configuration

Installation

npm install -D build-hasher

Note: This package is designed for build tools and should be installed as a dev dependency since it's used during the build process, not at runtime.

Usage

import { hashAssets, updateHashedLinks } from 'build-hasher';

// Hash assets
const manifest = hashAssets({
  outputDir: './dist',
  extensions: ['.js', '.css', '.png'],
  ignoredFiles: ['vendor.js']
});

// Update file references
updateHashedLinks({
  hashManifest: manifest,
  outputDir: './dist',
  extensions: ['.html']
});

API Reference

hashAssets(options)

Hashes files and returns a manifest of mappings.

Parameters:

  • outputDir (string) - Directory to search for files
  • extensions (string[]) - File extensions to hash
  • ignoredFiles (string[], optional) - Files to ignore

Returns: Record<string, string> - Original to hashed filename mappings

Example

const manifest = hashAssets({
  outputDir: './dist',
  extensions: ['.js', '.css', '.png', '.jpg'],
  ignoredFiles: ['vendor.js', 'legacy.css']
});

console.log(manifest);
// Output:
// {
//   'app.js': 'app.a1b2c3d4.js',
//   'styles.css': 'styles.e5f6g7h8.css',
//   'logo.png': 'logo.i9j0k1l2.png'
// }

updateHashedLinks(options)

Updates file references to use hashed filenames.

Parameters:

  • hashManifest (Record<string, string>) - Manifest from hashAssets()
  • outputDir (string) - Directory containing files to update
  • extensions (string[], optional) - File extensions to search (default: ['.html'])
  • files (string[], optional) - Additional files to update
  • replaceRule (Record<string, [string, string]>, optional) - Custom replace rules

Example

updateHashedLinks({
  hashManifest: manifest,
  outputDir: './dist',
  extensions: ['.html', '.php'],
  files: ['custom-template.tpl'],
  replaceRule: {
    '.html': ['src="', 'src="'],
    '.php': ['<?php echo "', '<?php echo "']
  }
});

Examples

Basic Usage

import { hashAssets, updateHashedLinks } from 'build-hasher';

const manifest = hashAssets({
  outputDir: './dist',
  extensions: ['.js', '.css', '.png'],
  ignoredFiles: ['vendor.js']
});

updateHashedLinks({
  hashManifest: manifest,
  outputDir: './dist',
  extensions: ['.html']
});

Custom Configuration

const manifest = hashAssets({
  outputDir: './build',
  extensions: ['.js', '.css', '.woff2'],
  ignoredFiles: ['vendor/jquery.js', 'test-*.js']
});

updateHashedLinks({
  hashManifest: manifest,
  outputDir: './build',
  extensions: ['.html', '.php'],
  replaceRule: {
    '.html': ['src="', 'src="'],
    '.php': ['<?php echo "', '<?php echo "']
  }
});

Build Tool Integration

// webpack.config.js
import { hashAssets, updateHashedLinks } from 'build-hasher';

class AssetHasherPlugin {
  apply(compiler) {
    compiler.hooks.afterEmit.tap('AssetHasherPlugin', (compilation) => {
      const manifest = hashAssets({
        outputDir: compilation.options.output.path,
        extensions: ['.js', '.css']
      });

      updateHashedLinks({
        hashManifest: manifest,
        outputDir: compilation.options.output.path,
        extensions: ['.html']
      });
    });
  }
}

Build Scripts

{
  "scripts": {
    "build": "webpack && node scripts/hash-assets.js",
    "hash-assets": "node scripts/hash-assets.js"
  }
}
// scripts/hash-assets.js
import { hashAssets, updateHashedLinks } from 'build-hasher';

const manifest = hashAssets({
  outputDir: './dist',
  extensions: ['.js', '.css', '.png']
});

updateHashedLinks({
  hashManifest: manifest,
  outputDir: './dist',
  extensions: ['.html']
});

TypeScript

import { hashAssets, updateHashedLinks, type HashAssetsOptions } from 'build-hasher';

const options: HashAssetsOptions = {
  outputDir: './dist',
  extensions: ['.js', '.css'],
  ignoredFiles: ['vendor.js']
};

const manifest = hashAssets(options);
updateHashedLinks({ hashManifest: manifest, outputDir: './dist' });

CommonJS

const { hashAssets, updateHashedLinks } = require('build-hasher');

const manifest = hashAssets({
  outputDir: './dist',
  extensions: ['.js', '.css']
});

updateHashedLinks({
  hashManifest: manifest,
  outputDir: './dist'
});

Requirements

Node.js >= 18.0.0

License

MIT © ivnvMkhl