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

commons-version-webpack-plugin

v1.0.1

Published

## 使用

Downloads

4

Readme

commons-version-webpack-plugin

使用

npm install commons-version-webpack-plugin

var CommonsVersionPlugin = require('commons-version-webpack-plugin');

// ... 省略

config.plugins.push(
    new CommonsVersionPlugin({
        commonsName: 'commons',
        onFileName: function (hash) {
            console.log('onFileName');
            return 'js/[name].' + hash.slice(0, 8) + '.bundle.js';
        }
    })
)

背景

也许你接触过CommonsChunkPlugin,通过它来打公共模块,并做long cache,可能会有这样的代码

// webpack.config.js
var config = {
    entry: {
        'commons': [
            'react', 'react-dom'
        ],
        'index': [
            './example/index'
        ]
    },
    output: {
        path: path.join(__dirname, 'build'),
        filename: '[name].[chunkhash:8].bundle.js',
        chunkFilename: '[id].[chunkhash:8].bundle.js',
        publicPath: '/static/build/'
    },
    plugins: [
        new webpack.NoErrorsPlugin(),
        new CommonsChunkPlugin({
            name: 'commons',
            filename: 'js/[name].[hash:8].bundle.js'
        })
    ]
};

兴高采烈打包出来是 js/commons.7279fdf6.bundle.js。 改下入口文件./example/index.js的代码,如添加console.log('gmfe'),再次打包出来文件是js/commons.fceb5fbe.bundle.js

问题来了,公共文件并没有修改,怎么hash变了呢?

对比两次commons.xxx.js的文件可以发现,区别是index.[hash:8].bundle.js的hash值。 也就是说index.js文件变了,index的hash肯定变,所以commons的hash也变。

为啥commons会有index的hash值呢? 细心的同学会发现文件开头有这么一行注释// webpackBootstrap,webpackBootstrap中包含了各个模块的的加载信息。

所以搞了一个插件,只对commons依赖的源代码算hash,这样就可以保证commons的hash不变了。

and

目前只自己团队在用,场景比较局限,功能实现简单,同时webpack内部比较复杂,文档比较缺,有bug在所难免,提issue吧。