Skip to content
Merged
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
17 changes: 17 additions & 0 deletions config/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable import/no-dynamic-require */
const path = require('path');
const fs = require('fs');
const { execSync } = require('child_process');
const { defineConfig } = require('@rspack/cli');
const { TsCheckerRspackPlugin } = require('ts-checker-rspack-plugin');
const dotenv = require('dotenv');
Expand Down Expand Up @@ -30,6 +31,20 @@ module.exports = (webpackEnv, argv) => {
throw Error(`Invalid mode passed: ${mode}`);
}

// Extract the git branch and commit from environment variables or git commands
let gitBranch = env.GIT_BRANCH;
let gitCommitHash = env.GIT_COMMIT_HASH;
try {
if (!gitBranch) {
gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
}
if (!gitCommitHash) {
gitCommitHash = execSync('git rev-parse --short HEAD').toString().trim();
}
} catch (e) {
console.warn('Could not determine git branch/commit hash via git command, falling back to environment variables or undefined.');
}

const isDevServerOnly = env.dev_server_only?.toLowerCase() === 'true';
const devtool = env.devtool?.toLowerCase() === 'false' ? false : (env.devtool || (isEnvDevelopment ? 'eval-source-map' : 'source-map'));
const isReactRefresh = isDevServer && isEnvDevelopment;
Expand Down Expand Up @@ -388,6 +403,8 @@ module.exports = (webpackEnv, argv) => {
'process.env.__APP_NAME__': JSON.stringify(appPkg.name),
'process.env.__APP_DISPLAY_NAME__': JSON.stringify(appPkg.displayName || appPkg.name),
'process.env.__VERSION__': JSON.stringify(appPkg.version),
'process.env.__GIT_BRANCH__': JSON.stringify(gitBranch),
'process.env.__GIT_COMMIT_HASH__': JSON.stringify(gitCommitHash),
'process.env.__LICENSE__': JSON.stringify(appPkg.license),
'process.env.__BUILD_ID__': JSON.stringify(buildId),
'process.env.__APP_CONTEXT__': JSON.stringify('/'),
Expand Down
Loading