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 🙏

© 2026 – Pkg Stats / Ryan Hefner

webpack-plugin-git-stamp

v1.0.1

Published

webpack插件,用于在构建时生成git相关信息

Readme

webpack-plugin-git-stamp

插件简介

webpack-plugin-git-stamp 是一个 Webpack 插件,用于在构建完成后记录 Git 相关的信息,包括分支名称、提交哈希、提交信息、提交作者、最新标签以及构建时间等。这些信息将被写入到指定的 JSON 文件中,帮助开发者追溯构建版本,避免版本不一致的问题。

功能特性

  • 自动获取 Git 相关信息:
    • 分支名称
    • 提交哈希
    • 提交信息
    • 提交作者
    • 最新标签
    • 构建时间
  • 将 Git 版本信息写入构建目录下的 JSON 文件
  • 适用于 Webpack 4,支持 Windows、Linux 和 macOS 等操作系统
  • 简单易用,可以帮助构建产物的版本追踪和问题排查

安装

使用 npm 或 yarn 将插件安装为开发依赖:

npm install --save-dev webpack-plugin-git-stamp

或者

yarn add --dev webpack-plugin-git-stamp

使用方法

在 Webpack 配置文件 webpack.config.js 中引入并使用该插件:

// webpack.config.js
const path = require('path');
const GitStampPlugin = require('webpack-plugin-git-stamp'); // 引入插件

module.exports = {
  // 其他 Webpack 配置...
  plugins: [
    new GitStampPlugin({
      outDir: 'build',           // 可选,指定输出目录,默认是 'dist'
      fileName: 'version.json'   // 可选,指定输出的 JSON 文件名称,默认是 'version.json'
    }),
  ],
};

插件选项

插件接受一个配置对象,支持以下选项:

  • outDirstring
    构建产物的输出目录,默认为 'dist'。可以设置为其他目录,如 'build'

  • fileNamestring
    输出的 JSON 文件名称,默认为 'version.json'。可以自定义文件名。

构建输出

在运行 webpack 构建后,插件会自动生成一个 JSON 文件,包含以下内容:

  • branch: 当前 Git 分支名称
  • commitHash: 最新提交的哈希值
  • commitMessage: 最新提交的信息
  • commitAuthor: 最新提交的作者
  • latestTag: 最新标签(如果有)
  • buildTime: 构建时间

该文件默认保存在构建目录(dist 或你指定的目录)下,文件名为 version.json

兼容性与注意事项

  • Git 依赖
    插件依赖于 Git 命令,确保在构建环境中安装了 Git 并且 Git 命令可用。如果是在 CI/CD 环境中构建,请确保构建环境配置了 Git。

  • 跨平台支持
    本插件在 Windows、Linux 和 macOS 等操作系统下均可正常工作。

  • 权限问题
    请确保构建目录具有写入权限,否则插件无法创建输出的 JSON 文件。

  • CI/CD 环境
    在某些 CI/CD 环境中,可能需要调整 Git 克隆策略以确保获取到完整的 Git 历史信息,避免因为浅克隆导致无法获取某些 Git 信息。

许可证

该插件采用 MIT License 开源许可证。