彩色标签 · 构建信息 · 控制台打印
Webpack / Rspack / Vite 插件,在 HTML 页面控制台注入彩色标签,展示构建信息:环境、Git 分支、Commit Hash、版本、自定义字段。
npm install @sprit/console-tag
# or
yarn add @sprit/console-tagimport { ConsoleTagRspackPlugin } from '@sprit/console-tag';
// rspack.config.ts
plugins: [
new HtmlRspackPlugin(),
new ConsoleTagRspackPlugin({
HtmlPlugin: HtmlRspackPlugin,
git: { branch: true, hash: 7 },
}),
]import { ConsoleTagVitePlugin } from '@sprit/console-tag';
// vite.config.ts
export default {
plugins: [
ConsoleTagVitePlugin({
git: { branch: true, hash: 7, version: true, lastCommitDateTime: true },
custom: () => ({ 构建版本: process.env.BUILD_VERSION ?? '-' }),
}),
],
}import { ConsoleTagWebpackPlugin } from '@sprit/console-tag';
// webpack.config.ts
plugins: [
new HtmlWebpackPlugin(),
new ConsoleTagWebpackPlugin({
HtmlPlugin: HtmlWebpackPlugin,
git: { branch: true, hash: 7 },
custom: () => ({ 构建版本: process.env.BUILD_VERSION ?? '-' }),
}),
]打开浏览器控制台,自动打印彩色标签:
NODE_ENVproductiongit 分支maingit hasha1b2c3d
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
NODE_ENV |
boolean |
true |
显示 NODE_ENV 环境变量 |
git.branch |
boolean |
true |
Git 分支名 |
git.hash |
number |
7 |
Commit hash 长度 |
git.version |
boolean |
false |
Git 版本标签 |
git.lastCommitDateTime |
boolean |
false |
最近提交时间 |
custom |
() => Record<string, string> |
— | 自定义键值对 |
import {
ConsoleTagWebpackPlugin, // Webpack 插件
ConsoleTagRspackPlugin, // Rspack 插件
ConsoleTagVitePlugin, // Vite 插件
Git, // Git 信息获取类
} from '@sprit/console-tag';MIT © 赵永盛
