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

git-info-build-plugin

v1.2.0

Published

构建插入git信息工具

Downloads

84

Readme

一个构建plugin插件,在 build 的时候自动在 index.html 中插入当前构建 git HEAD 节点的相关信息,以供排查构建版本

install

npm i git-info-build-plugin -D

引入

import { vitePluginGitInfoInject } from 'git-info-build-plugin';
// or

const { WebpackPluginGitInfoInject } = require('git-info-build-plugin');
// const { WebpackPluginGitInfoInject3 } = require('git-info-build-plugin');
  • WebpackPluginGitInfoInject webpack 4/5+ 构建环境引入

  • Webpack3PluginGitInfoInject webpack 3- 构建环境引入

  • vitePluginGitInfoInject vite 构建环境引入

  • options

  {
    "hash": true,
    "time": true,
    "branch": true,
    "tag": true,
    "console": true,
    "htmlFile": "index.html",
    "globalVarName": "__PROJECT_VERSION_INFO__",

    "outFile": "", // _version.txt 默认不输出
    "buildTime": true,
  }

在插入的信息中是否需要的相关信息:

  • hash 提交节点的hash串

  • time 提交节点的时间

  • branch 分支信息,如果有

  • tag HEAD 节点上有的tag信息

  • htmlFile 插入的html文件信息

  • globalVarName 插件html中的全局变量名,可为空

  • console 是否控制台输出

  • outFile 在build dist文件夹中输入一个文件,为空则不输出

  • buildTime 构建时间点

示例

// vite.config.js
import vue2 from '@vitejs/plugin-vue2';
import { vitePluginGitInfoInject } from 'git-info-build-plugin';

export default defineConfig({
  base: './',
  plugins: [
    vue2(),
    vitePluginGitInfoInject(options),
  ],
})
// vue.config.js / webpack.config.js
const { WebpackPluginGitInfoInject, /* Webpack3PluginGitInfoInject */ } = require('git-info-build-plugin');

module.exports = {
  // ...
  configureWebpack: (config) => {
    config.plugins.push(...[new WebpackPluginGitInfoInject(options)]);
  },

默认输出

  • console 控制台 输出日志
[git-info] {
    "commitHash": "xxxxxxxxxxxxxxxxxxxx",
    "commitTime": "2024-08-15 14:50:13",
    "gitBranch": "xxx-xxx",
    "gitTag": "xx-xx",
    "buildTime": "2024/8/15 5:34:30"
}
  • html文件新增脚本
<script>window.__PROJECT_VERSION_INFO__ = {"commitHash":"xxxxxxxxxxxxxxxxxxxx","commitTime":"2024-08-15 14:50:13","gitBranch":"xxx-xxx","gitTag":"xx-xx"};console.info("[git-info] ", window.__PROJECT_VERSION_INFO__);</script>
  • 带有 outFile 则会在对应dist文件夹内新建一个 文件内容,内容和上述一致