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

rehash-webpack-plugin

v1.0.2

Published

根据output中的hash配置和最终生成的文件内容计算的hash值,重新给文件命名

Downloads

3

Readme

  npm i -D rehash-webpack-plugin
  yarn add --dev rehash-webpack-plugin

Then, you can easily rename the emitted JS/CSS file using its md5 value.

The plugin will calculate the hash value based on the final webpack emitted assets' content, replacing the contenthash or chunkhash in the JS/CSS filename. Just follow these steps:

add the plugin to your webpack

Check and modify your webpack configuration files as appropriate Depending on whether the production environment exports sourcemap files or not, there are two recommended ways to set this up.

2.1 devtool is set to none of the source-map, nosources-source-map, hidden-nosources-source-map, hidden-source-map

for main configurations,

import RehashWebpackPlugin from 'rehash-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';

module.exports = {
  devtool: false,
  // ... Ignore other configurations ...
  output: {
    filename: '[contenthash].js',
     // for dynamic chunk
    chunkFilename: '[contenthash].js',
    hashFunction: 'md5',
    hashDigest: 'hex'
  },
  plugins: [
    new RehashWebpackPlugin({hashType:'contenthash'}),
    new MiniCssExtractPlugin({
        filename: '[contenthash].css',
        // for dynamic chunk
        chunkFilename: '[contenthash].css', 
    })
  ]
}

Note: ** All the files will be rename with the new hash. **

2.2 devtool is set to one of the source-map, nosources-source-map, hidden-nosources-source-map, hidden-source-map

In this case, the production environment generates a sourcemap file for the JS/CSS files, and output needs to be configured with the following filename and chunkFilename

import RehashWebpackPlugin from 'rehash-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';

module.exports = {
  devtool: 'source-map',
  // ... Ignore other configurations ...
  output: {
    filename: `[chunkhash]${RehashWebpackPlugin.specialSeparator}.js.js`,
     // for dynamic chunk
    chunkFilename: '[contenthash].js',
    hashFunction: 'md5',
    hashDigest: 'hex'
  },
  plugins: [
    new RehashWebpackPlugin({hashType:'chunkhash'}),
    new MiniCssExtractPlugin({
        filename:  `[chunkhash]${RehashWebpackPlugin.specialSeparator}.css.css`,
        // for dynamic chunk
        chunkFilename: '[contenthash].css', 
    })
  ]
}

Note: ** Only the main file(not including the dynamic file) will be renamed with the new hash. **

This is because if contenthash is also used in the output.filename configuration, this causes the sourcemap filename to be modified once during the processAssets phase, and the hash value generated based on the contents of the file in the intermediate state is not the correct hash value.

options.hashType

string, contenthash | chunkhash, default to chunkhash

Note: This setting depends on whether the sourcemap file will be generated. See above.

Contributors

KnightWu (@wulijian) [email protected]

Special Notes

This plugin is partial based on (webpack-plugin-hash-output)[https://github.com/scinos/webpack-plugin-hash-output], thanks for their work.