mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-05-10 15:15:41 -05:00
fix: derive workbox version from package.json at build time
Instead of hardcoding the workbox version string in the service worker, read it from workbox-precaching/package.json via Vite's define option. This ensures the service worker always references the correct workbox version that is actually installed. Resolves #2549
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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<string, string>) {
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user