diff --git a/frontend/src/sw.ts b/frontend/src/sw.ts index 07c26685f..b23613d4e 100644 --- a/frontend/src/sw.ts +++ b/frontend/src/sw.ts @@ -1,9 +1,10 @@ import {getFullBaseUrl} from './helpers/getFullBaseUrl' declare let self: ServiceWorkerGlobalScope +declare const __WORKBOX_VERSION__: string const fullBaseUrl = getFullBaseUrl() -const workboxVersion = 'v7.3.0' +const workboxVersion = __WORKBOX_VERSION__ importScripts(`${fullBaseUrl}workbox-${workboxVersion}/workbox-sw.js`) workbox.setConfig({ diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index df830027d..46ce0eb22 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -4,6 +4,7 @@ import {configDefaults} from 'vitest/config' import vue from '@vitejs/plugin-vue' import {URL, fileURLToPath} from 'node:url' import {dirname, resolve} from 'node:path' +import {readFileSync} from 'node:fs' import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite' import {VitePWA} from 'vite-plugin-pwa' @@ -103,8 +104,14 @@ export default defineConfig(({command, mode}) => { }) function getBuildConfig(env: Record) { + const workboxPkgPath = resolve(dirname(pathSrc), 'node_modules/workbox-precaching/package.json') + const workboxVersion = JSON.parse(readFileSync(workboxPkgPath, 'utf-8')).version + return { base: env.VIKUNJA_FRONTEND_BASE, + define: { + __WORKBOX_VERSION__: JSON.stringify(`v${workboxVersion}`), + }, // https://vitest.dev/config/ test: { environment: 'happy-dom',