vite 取得 git 相關資訊
安裝擴充 vite-plugin-node-polyfills
為了安裝 node 擴充功能 child_process
連結
安裝指令
1 2 3 4 5 6 7 8
| # npm npm install --save-dev vite-plugin-node-polyfills
# pnpm pnpm install --save-dev vite-plugin-node-polyfills
# yarn yarn add --dev vite-plugin-node-polyfills
|
讀取資料
引入套件
1 2
| import { nodePolyfills } from 'vite-plugin-node-polyfills'; import { execSync } from 'child_process';
|
取得資料
1 2 3 4 5 6 7 8 9 10 11
| const commitDate = execSync('git log -1 --format=%cI').toString().trimEnd();
const branchName = execSync('git rev-parse --abbrev-ref HEAD').toString().trimEnd();
const commitHash = execSync('git rev-parse HEAD').toString().trimEnd();
const lastCommitMessage = execSync('git show -s --format=%s').toString().trimEnd();
const tag = execSync('git tag', { encoding: 'utf-8' }).trim().split('\n');
|
參考
連結