diff --git a/packages/pxweb2/index.html b/packages/pxweb2/index.html index a5508f3f6..d72dd1876 100644 --- a/packages/pxweb2/index.html +++ b/packages/pxweb2/index.html @@ -13,7 +13,7 @@ href="./images/favicon-darkmode.svg" /> - + - +
diff --git a/packages/pxweb2/src/app/util/content/localeContent.ts b/packages/pxweb2/src/app/util/content/localeContent.ts index 5e308868b..3b4620e93 100644 --- a/packages/pxweb2/src/app/util/content/localeContent.ts +++ b/packages/pxweb2/src/app/util/content/localeContent.ts @@ -24,7 +24,7 @@ export async function fetchLocaleContent( const fetchPromise = (async () => { try { const res = await fetch( - `./content/${key}/content.json?v=${__BUILD_DATE__}`, + `./content/${key}/content.json?v=${__APP_VERSION__}`, { cache: 'no-store', }, diff --git a/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx b/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx index ea3334c41..0d2a13d8b 100644 --- a/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx +++ b/packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; -const ICON_MAP_URL = `./icons/topicIconMap.json?v=${__BUILD_DATE__}`; +const ICON_MAP_URL = `./icons/topicIconMap.json?v=${__APP_VERSION__}`; const ICON_BASE_PATH = './icons/topic'; export type TopicIconComponents = { diff --git a/packages/pxweb2/src/i18n/config.ts b/packages/pxweb2/src/i18n/config.ts index 20bc98052..cc856a7a7 100644 --- a/packages/pxweb2/src/i18n/config.ts +++ b/packages/pxweb2/src/i18n/config.ts @@ -32,7 +32,7 @@ const initPromise = i18n .use(languageDetector) .init({ backend: { - loadPath: `${config.baseApplicationPath}locales/{{lng}}/translation.json?v=${__BUILD_DATE__}`, + loadPath: `${config.baseApplicationPath}locales/{{lng}}/translation.json?v=${__APP_VERSION__}`, }, fallbackLng: config.language.fallbackLanguage, defaultNS, diff --git a/packages/pxweb2/src/vite-env.d.ts b/packages/pxweb2/src/vite-env.d.ts new file mode 100644 index 000000000..41fad5b54 --- /dev/null +++ b/packages/pxweb2/src/vite-env.d.ts @@ -0,0 +1 @@ +declare const __APP_VERSION__: string; diff --git a/packages/pxweb2/vite.config.ts b/packages/pxweb2/vite.config.ts index 57066a49e..663ae10be 100644 --- a/packages/pxweb2/vite.config.ts +++ b/packages/pxweb2/vite.config.ts @@ -3,6 +3,10 @@ import react, { reactCompilerPreset } from '@vitejs/plugin-react'; import babel from '@rolldown/plugin-babel'; import path from 'path'; import { virtualModulePlugin } from './vite-plugin-virtual-module'; +import pkg from '../../package.json'; + +const buildNumber = + process.env.BUILD_NUMBER ?? process.env.GITHUB_RUN_NUMBER ?? 'local'; // Custom plugin to handle theme CSS injection const themeInjectorPlugin = (): Plugin => ({ @@ -10,16 +14,16 @@ const themeInjectorPlugin = (): Plugin => ({ transformIndexHtml(html) { // Remove the theme CSS link from the original HTML html = html.replace( - '', + '', '', ); // Inject it at the end of head to ensure it loads last html = html.replace( '', - '', + '', ); // Replace cache busting build date placeholder - return html.replace(/__BUILD_DATE__/g, new Date().toISOString()); + return html.replace(/__APP_VERSION__/g, `${pkg.version}+${buildNumber}`); }, }); @@ -55,9 +59,6 @@ export default defineConfig({ }, define: { // Used for cache busting of configuration files. - // Since we don't update pkg.version on release yet, we use build date instead. - // import pkg from './package.json'; - // __BUILD_VERSION__: JSON.stringify(pkg.version), - __BUILD_DATE__: JSON.stringify(new Date().toISOString()), + __APP_VERSION__: JSON.stringify(`${pkg.version}+${buildNumber}`), }, });