Skip to content

i-like-robots/reliable-module-ids-plugin

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Reliable Module IDs Plugin

GitHub license Build Status npm version Greenkeeper badge

This Webpack 4 plugin provides more reliable module IDs for improved long-term caching and code reuse between project installations and builds. It is intended to bridge the gap until we can use the deterministic IDs feature in Webpack 5.

Installation

This is a Node.js module available through the npm registry. Node 8 and Webpack 4.38 or higher are required.

Installation is done using the npm install command:

$ npm install --save-dev reliable-module-ids-plugin

Once installed the plugin can be added to your Webpack plugins configuration:

const ReliableModuleIdsPlugin = require('reliable-module-ids-plugin')

module.exports = {
  //...
  plugins: [
    new ReliableModuleIdsPlugin({
      // options
    })
  ]
}

If you have already configured optimization.moduleIds you should set this to false so Webpack will defer to the provided algorithm.

Options

hashFunction

The hashing algorithm to use, defaults to 'md5'. All functions from Node.JS' crypto.createHash are supported.

hashDigest

The encoding to use when generating the hash, defaults to 'hex'. All encodings from Node.JS' hash.digest are supported.

hashDigestLength

The prefix length of the hash digest to use, defaults to 8. Note that some generated IDs might be longer than specified here, to avoid module ID collisions.

Motivation

Module IDs play an important part in Webpack's content hashing algorithm. For the assets we compile with Webpack to be long-term cacheable and consistent over time we need to ensure the module ID algorithm is deterministic. By default Webpack will use numerical module IDs when run in production mode but because these IDs are assigned incrementally in the order that modules are added to the dependency graph these will naturally change over time. Webpack already provides alternatives for this; named which is the module's path relative to the project root and hashed which is a hash of this path, however if you use npm then these module paths are not deterministic and can change over time and between environments.

Prior Art

This plugin is based upon Webpack's built-in HashedModuleIdsPlugin by Tobias Koppers and uses the node_modules path normalization as demonstrated in the SimpleNamedModulesPlugin by Tomer Brisker.

Development

This project uses Prettier for automatic code formatting and is tested with Jasmine.

License

This package is MIT licensed.

About

πŸ†” A Webpack plugin to generate more consistent module IDs

Resources

License

Stars

Watchers

Forks

Packages

No packages published