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 🙏

© 2024 – Pkg Stats / Ryan Hefner

webpack-stable-module-id-and-hash

v1.0.5

Published

To provide stable module id and reliable content chunkhash

Downloads

47

Readme

WebpackStableModuleIdAndHash

To provide stable module id and reliable content chunkhash in webpack 1.x, help u make long term cache easily.

Usage

npm install webpack-stable-module-id-and-hash --save-dev

Then new a plugin in plugins webpack options, only use it in Production stage build,use OccurrenceOrderPlugin for Development is enough.

var WebpackStableModuleIdAndHash = require('webpack-stable-module-id-and-hash');
...
plugins: [
...
new WebpackStableModuleIdAndHash()
...
]

Why

Here related discuss from github issue

Target

  • Every output [chunkhash] should be calcuated (md5) by its dependencies module contents.
  • Every module ID should be stable and only if changes because correspond module file path (or content) changes.

How

Chunkhash

Like webpack-md5-hash,it calcuate chunkhash by dependen module content.

But webpack-md5-hash has a shortcoming:

Since module id is not stable, webpack-md5-hash sort modules by id may lead some unexpect output, e.p. chunkhash is not stable or same chunkhash for different content of output chunk(module id change).

Stable Module Id

Here some option or plugins support by webpack 1.x, like OccurrenceOrderPlugin, recordsPath, DllPlugin & DllReferencePlugin ,they all try to give stable module id,but can not 100% fix problem or require you to check in extra files.

Webpack 2 may fix most part of them with HashedModuleIdsPlugin

Like what HashedModuleIdsPlugin to do, juse one more thing that it converts the hash to num because webpack 1.x just accept num as module id.

OMG!! Forgive my poor English. Just checkout the source code.

Module ID collisions may cause builds to fail

This plugin calculates a predictable hash values based on the module file names. A hashin algorithm based on MD5 is used to calculate the hash value. As with any hash value, collisions are rare, but possible. In the event of a collision, a webpack-stable-module-id-and-hash module id collision error is thrown during the Webpack build.

In such a situation you can try to choose a different seed value to get different module IDs that may not collide.

The probability of a collision depends on the hashSize option. By default 53 bits are used, which allow 9007199254740992 possible module IDs. This means that the probability of a collision is 0.0000000000000011102% multiplied by the number of modules in your project.

chunk-hash length

This plugin adds the values of hashSize and seed to the chunk-hash string. That's necessary because these settings influence the module ids contained within the chunks, but not the MD5 chunk hash itself. Therefore, the values must become part of the chunk-hash used in the filename to make it unique.

Webpack by default shortens the resulting hash string to 20 characters, reducing the entropy of the MD5 hash.

In practice, that shouldn't be an issue. But if you want to have a better hash then you can adjust the output.hashDigestLength Webpack setting to a value higher than 20.

For example, to compensate the reduced entropy caused by webpack-stable-module-id-and-hash you might use a setting like this:

  //...
  output: {
    //...
    hashDigestLength: 30
  }

Options

The plugin acceps an object with these optional properties:

  • hashSize = Number of bits to use for the module ID. Defaults to the maximum, 53 bits. Large hash sizes greatly reduce the probability of a collision but lead also to very large module ID numbers for the generated code, which might slightly incrase Webpack chunk sizes.
  • seed = Any number between 0 and 31. Different "seed" values cause completely different module IDs. This is useful in the event of a collision.