mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat(nuxt): allow configuring interval for checking app update (#27324)
This commit is contained in:
parent
34ea5ae2f2
commit
5bff730614
@ -4,6 +4,8 @@ import type { NuxtAppManifestMeta } from '../composables/manifest'
|
||||
import { onNuxtReady } from '../composables/ready'
|
||||
// @ts-expect-error virtual file
|
||||
import { buildAssetsURL } from '#internal/nuxt/paths'
|
||||
// @ts-expect-error virtual file
|
||||
import { outdatedBuildInterval } from '#build/nuxt.config.mjs'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
if (import.meta.test) { return }
|
||||
@ -13,7 +15,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
async function getLatestManifest () {
|
||||
const currentManifest = await getAppManifest()
|
||||
if (timeout) { clearTimeout(timeout) }
|
||||
timeout = setTimeout(getLatestManifest, 1000 * 60 * 60)
|
||||
timeout = setTimeout(getLatestManifest, outdatedBuildInterval)
|
||||
try {
|
||||
const meta = await $fetch<NuxtAppManifestMeta>(buildAssetsURL('builds/latest.json') + `?${Date.now()}`)
|
||||
if (meta.id !== currentManifest.id) {
|
||||
@ -25,5 +27,5 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
}
|
||||
}
|
||||
|
||||
onNuxtReady(() => { timeout = setTimeout(getLatestManifest, 1000 * 60 * 60) })
|
||||
onNuxtReady(() => { timeout = setTimeout(getLatestManifest, outdatedBuildInterval) })
|
||||
})
|
||||
|
@ -508,8 +508,10 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
global: true,
|
||||
})
|
||||
|
||||
if (nuxt.options.experimental.checkOutdatedBuildInterval !== false) {
|
||||
addPlugin(resolve(nuxt.options.appDir, 'plugins/check-outdated-build.client'))
|
||||
}
|
||||
}
|
||||
|
||||
nuxt.hooks.hook('builder:watch', (event, relativePath) => {
|
||||
const path = resolve(nuxt.options.srcDir, relativePath)
|
||||
|
@ -413,6 +413,7 @@ export const nuxtConfigTemplate: NuxtTemplate = {
|
||||
`export const vueAppRootContainer = ${ctx.nuxt.options.app.rootId ? `'#${ctx.nuxt.options.app.rootId}'` : `'body > ${ctx.nuxt.options.app.rootTag}'`}`,
|
||||
`export const viewTransition = ${ctx.nuxt.options.experimental.viewTransition}`,
|
||||
`export const appId = ${JSON.stringify(ctx.nuxt.options.appId)}`,
|
||||
`export const outdatedBuildInterval = ${ctx.nuxt.options.experimental.checkOutdatedBuildInterval}`,
|
||||
].join('\n\n')
|
||||
},
|
||||
}
|
||||
|
@ -319,6 +319,14 @@ export default defineUntypedSchema({
|
||||
*/
|
||||
appManifest: true,
|
||||
|
||||
/**
|
||||
* Set the time interval (in ms) to check for new builds. Disabled when `experimental.appManifest` is `false`.
|
||||
*
|
||||
* Set to `false` to disable.
|
||||
* @type {number | false}
|
||||
*/
|
||||
checkOutdatedBuildInterval: 1000 * 60 * 60,
|
||||
|
||||
/**
|
||||
* Set an alternative watcher that will be used as the watching service for Nuxt.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user