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 packages/pxweb2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
href="./images/favicon-darkmode.svg"
/>
<link rel="stylesheet" href="src/styles.scss" />
<link rel="stylesheet" href="./theme/variables.css?v=__BUILD_DATE__" />
<link rel="stylesheet" href="./theme/variables.css?v=__APP_VERSION__" />
<link
rel="preload"
href="./fonts/PxWeb-font-500.ttf"
Expand Down Expand Up @@ -56,7 +56,7 @@
crossorigin="anonymous"
type="font/ttf"
/>
<script src="./config/config.js?v=__BUILD_DATE__"></script>
<script src="./config/config.js?v=__APP_VERSION__"></script>
</head>
<body>
<div id="root"></div>
Expand Down
2 changes: 1 addition & 1 deletion packages/pxweb2/src/app/util/content/localeContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/pxweb2/src/app/util/hooks/useTopicIcons.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion packages/pxweb2/src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/pxweb2/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const __APP_VERSION__: string;
15 changes: 8 additions & 7 deletions packages/pxweb2/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ 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 => ({
name: 'theme-injector',
transformIndexHtml(html) {
// Remove the theme CSS link from the original HTML
html = html.replace(
'<link rel="stylesheet" href="./theme/variables.css?v=__BUILD_DATE__" />',
'<link rel="stylesheet" href="./theme/variables.css?v=__APP_VERSION__" />',
'',
);
// Inject it at the end of head to ensure it loads last
html = html.replace(
'</head>',
'<link rel="stylesheet" href="./theme/variables.css?v=__BUILD_DATE__" /></head>',
'<link rel="stylesheet" href="./theme/variables.css?v=__APP_VERSION__" /></head>',
);
// Replace cache busting build date placeholder
return html.replace(/__BUILD_DATE__/g, new Date().toISOString());
return html.replace(/__APP_VERSION__/g, `${pkg.version}+${buildNumber}`);
},
});

Expand Down Expand Up @@ -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}`),
},
});
Loading