diff --git a/craco.config.js b/craco.config.js
index 26a9c16..faca59c 100644
--- a/craco.config.js
+++ b/craco.config.js
@@ -81,8 +81,8 @@
new AntdDayjsWebpackPlugin(),
gitRevisionPlugin,
new DefinePlugin({
- "__GIT_VERSION__": JSON.stringify(gitRevisionPlugin.version()),
- "__GIT_COMMIT_HASH__": JSON.stringify(gitRevisionPlugin.commithash()),
+ "__GIT_VERSION__": DefinePlugin.runtimeValue(() => JSON.stringify(gitRevisionPlugin.version()), []),
+ "__GIT_COMMIT_HASH__": DefinePlugin.runtimeValue(() => JSON.stringify(gitRevisionPlugin.commithash()), []),
"__BUILD_TIME__": DefinePlugin.runtimeValue(Date.now),
"__GIT_COMMITS__": JSON.stringify(commits)
})
diff --git a/src/layout/nav/Brand.tsx b/src/layout/nav/Brand.tsx
index 36e74ab..ad45201 100644
--- a/src/layout/nav/Brand.tsx
+++ b/src/layout/nav/Brand.tsx
@@ -1,6 +1,7 @@
// Copyright (c) 2020-2021 Drew Lemmy
// This file is part of KristWeb 2 under GPL-3.0.
// Full details: https://github.com/tmpim/KristWeb2/blob/master/LICENSE.txt
+import { useDebugValue } from "react";
import { Tag } from "antd";
import { useTranslation } from "react-i18next";
@@ -14,6 +15,8 @@
import packageJson from "../../../package.json";
+declare const __GIT_VERSION__: string;
+
const prereleaseTagColours: { [key: string]: string } = {
"dev": "red",
"alpha": "orange",
@@ -21,6 +24,9 @@
"rc": "green"
};
+const devEnvs = ["development", "local", "test"];
+const dirtyRegex = /-dirty$/;
+
export function Brand(): JSX.Element {
const { t } = useTranslation();
@@ -31,11 +37,18 @@
const patch = semverPatch(version);
const prerelease = semverPrerelease(version);
+ // Determine if the 'dev' tag should be shown
+ // Replaced by webpack DefinePlugin and git-revision-webpack-plugin
+ const gitVersion: string = __GIT_VERSION__;
+ const isDirty = dirtyRegex.test(gitVersion);
+ const isDev = devEnvs.includes(process.env.NODE_ENV || "development");
+
// Convert semver prerelease parts to Bootstrap badge
+ const tagContents = isDirty || isDev ? ["dev"] : prerelease;
let tag = null;
- if (prerelease && prerelease.length) {
- const variant = prereleaseTagColours[prerelease[0]] || undefined;
- tag =