我想将提交哈希添加到我的反应应用程序中。通常,我使用 webpack 添加它,但这个项目他们使用 vite.config.js。我可以知道如何将提交哈希注入 vite 以及如何在 React 组件中使用它。
谢谢。
const commitHash = require('child_process').execSync('git rev-parse --short HEAD').toString();
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
const commitHash = require('child_process')
.execSync('git rev-parse --short HEAD')
.toString();
export default defineConfig({
define: {
__COMMIT_HASH__: JSON.stringify(commitHash),
},
plugins: [react()],
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5436 次 |
| 最近记录: |