Skip to content

@neosjs/unplugin-build-message ​

基于 unplugin 的构建信息打印插件,支持 Vite、Rollup、esbuild。构建启动时清空终端,打印项目名称、当前版本、当前分支与最近一次 Git 提交(提交者 / 提交信息 / 提交时间),让每次构建的上下文一目了然。

安装 ​

sh
pnpm add @neosjs/unplugin-build-message -D
sh
npm install @neosjs/unplugin-build-message -D
sh
yarn add @neosjs/unplugin-build-message -D

快速上手 ​

Vite ​

ts
// vite.config.ts
import buildMessage from '@neosjs/unplugin-build-message/vite'

export default defineConfig({
  plugins: [
    buildMessage({
      /* options */
    })
  ]
})

Rollup ​

ts
// rollup.config.js
import buildMessage from '@neosjs/unplugin-build-message/rollup'

export default {
  plugins: [
    buildMessage({
      /* options */
    })
  ]
}

esbuild ​

ts
import buildMessage from '@neosjs/unplugin-build-message/esbuild'
// esbuild.config.js
import { build } from 'esbuild'

build({
  /* ... */
  plugins: [
    buildMessage({
      /* options */
    })
  ]
})

配置项 ​

插件在 buildStart 阶段读取项目信息并打印;未初始化 Git 仓库时会提示无法获取 git 信息。

ts
interface Options {
  /** 项目根目录,默认 process.cwd() */
  root?: string
  /** 读取 package.json 的范围:字符串数组,或按名称过滤的映射 */
  package?: string[] | Record<string, boolean | null | undefined>
  /** GitHub 仓库地址 */
  github?: string
  /** 自定义 git 信息获取命令,键为命令名,值为 (git: SimpleGit) => Promise<any> | any */
  git?: Record<string, (git: SimpleGit) => Promise<any> | any>
  /** 打印信息的前缀 */
  prefix?: string
}

打印内容包括:

text
项目名称: your-app
当前版本: 1.0.0
当前分支: main
最近一次提交记录如下:
提交者: xxx
提交信息: feat: xxx
提交时间: 2024/1/1 12:00:00