Skip to content

Commit

Permalink
add package version and commit id global constants
Browse files Browse the repository at this point in the history
  • Loading branch information
vsergeev committed Feb 26, 2023
1 parent 133fe06 commit 06962f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/// <reference types="svelte" />
/// <reference types="vite/client" />

declare global {
interface Window {
__APP_VERSION__: string;
__APP_COMMIT_ID__: string;
}
}

export {};
14 changes: 14 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

import * as child_process from 'child_process';

/* Get commit id */
let commitId: string;
try {
commitId = child_process.execSync('git rev-parse --short HEAD 2>/dev/null').toString();
} catch {
commitId = 'unknown';
}

// https://vitejs.dev/config/
export default defineConfig({
base: '',
define: {
'window.__APP_VERSION__': JSON.stringify(process.env.npm_package_version),
'window.__APP_COMMIT_ID__': JSON.stringify(commitId),
},
plugins: [svelte()],
});

0 comments on commit 06962f3

Please sign in to comment.