Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"type": "module",
"scripts": {
"dev": "VITE_GIT_SHA=`git rev-parse --short HEAD` GENERATE_SOURCEMAP=false vite",
"build": "VITE_GIT_SHA=`git rev-parse --short HEAD` tsc && vite build",
"dev": "GENERATE_SOURCEMAP=false vite",
"build": "tsc && vite build",
"lint": "eslint ./",
"type-check": "tsc --noEmit",
"test": "vitest run",
Expand Down
14 changes: 10 additions & 4 deletions src/App/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ const linkStyle = {
},
};

const gitSha = import.meta.env.VITE_GIT_SHA;

const links = [
{ text: 'GitHub', url: 'https://github.com/coder13/delegateDashboard' },
{ text: 'Contact', url: 'mailto:choover11@gmail.com' },
{
text: `${import.meta.env.VITE_GIT_SHA}`,
url: `https://github.com/coder13/delegateDashboard/commit/${import.meta.env.VITE_GIT_SHA}`,
},
...(gitSha
? [
{
text: gitSha,
url: `https://github.com/coder13/delegateDashboard/commit/${gitSha}`,
},
]
: []),
];

const Footer = () => {
Expand Down
15 changes: 15 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import react from '@vitejs/plugin-react';
import { execSync } from 'child_process';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import svgrPlugin from 'vite-plugin-svgr';
import viteTsconfigPaths from 'vite-tsconfig-paths';

// Get git SHA, fallback to environment variable or undefined
const getGitSha = () => {
try {
// Try to get from git command
return execSync('git rev-parse --short HEAD').toString().trim();
} catch {
// Fallback to environment variable (useful for Netlify)
return process.env.VITE_GIT_SHA || process.env.COMMIT_REF?.substring(0, 7);
}
};

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), viteTsconfigPaths(), svgrPlugin(), VitePWA()],
define: {
'import.meta.env.VITE_GIT_SHA': JSON.stringify(getGitSha()),
},
});
Loading