mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-22 08:29:46 +00:00
feat: adding dev support for payload extraction
This commit is contained in:
parent
7bb9f414fa
commit
b3d5c9836e
@ -9,12 +9,10 @@ import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs'
|
||||
export default defineNuxtPlugin({
|
||||
name: 'nuxt:payload',
|
||||
setup (nuxtApp) {
|
||||
// TODO: Support dev
|
||||
if (import.meta.dev) { return }
|
||||
|
||||
// Load payload after middleware & once final route is resolved
|
||||
useRouter().beforeResolve(async (to, from) => {
|
||||
if (to.path === from.path) { return }
|
||||
// Forcefully load payload in dev mode, to support payload extraction at page refresh.
|
||||
if (to.path === from.path && !import.meta.dev) { return }
|
||||
const payload = await loadPayload(to.path)
|
||||
if (!payload) { return }
|
||||
Object.assign(nuxtApp.static.data, payload.data)
|
||||
|
@ -591,7 +591,7 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
}
|
||||
|
||||
// Add prerender payload support
|
||||
if (!nuxt.options.dev && nuxt.options.experimental.payloadExtraction) {
|
||||
if (nuxt.options.experimental.payloadExtraction) {
|
||||
addPlugin(resolve(nuxt.options.appDir, 'plugins/payload.client'))
|
||||
}
|
||||
|
||||
@ -711,7 +711,7 @@ export default defineNuxtPlugin({
|
||||
nitro.options.replace['process.env.NUXT_PAYLOAD_EXTRACTION'] = String(!!nuxt.options.experimental.payloadExtraction)
|
||||
nitro.options._config.replace!['process.env.NUXT_PAYLOAD_EXTRACTION'] = String(!!nuxt.options.experimental.payloadExtraction)
|
||||
|
||||
if (!nuxt.options.dev && nuxt.options.experimental.payloadExtraction) {
|
||||
if (nuxt.options.experimental.payloadExtraction) {
|
||||
addPlugin(resolve(nuxt.options.appDir, 'plugins/payload.client'))
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,9 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
// Whether we are prerendering route
|
||||
const _PAYLOAD_EXTRACTION = import.meta.prerender && process.env.NUXT_PAYLOAD_EXTRACTION && !ssrContext.noSSR && !isRenderingIsland
|
||||
const payloadURL = _PAYLOAD_EXTRACTION ? joinURL(ssrContext.runtimeConfig.app.cdnURL || ssrContext.runtimeConfig.app.baseURL, url, process.env.NUXT_JSON_PAYLOADS ? '_payload.json' : '_payload.js') + '?' + ssrContext.runtimeConfig.app.buildId : undefined
|
||||
if (import.meta.prerender) {
|
||||
|
||||
const pagePrerenderedInDev = import.meta.dev && (!!routeOptions.prerender || isRenderingPayload)
|
||||
if (pagePrerenderedInDev || import.meta.prerender) {
|
||||
ssrContext.payload.prerenderedAt = Date.now()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user