mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
refactor: inline staticAssetsBase in state chunk for full-static (#7401)
* refactor(vue-app): use NUXT.serverRendered instead of NUXT.spa * refactor: inline staticAssetsBase into state.js chunk * revert: unwanted change [release]
This commit is contained in:
parent
60ae0fb011
commit
1e53e38f8d
@ -305,7 +305,7 @@ export default {
|
|||||||
async fetchPayload(route) {
|
async fetchPayload(route) {
|
||||||
route = (route.replace(/\/+$/, '') || '/').split('?')[0]
|
route = (route.replace(/\/+$/, '') || '/').split('?')[0]
|
||||||
try {
|
try {
|
||||||
const src = urlJoin(window.__NUXT_STATIC__, route, 'payload.js')
|
const src = urlJoin(window.<%= globals.context %>.staticAssetsBase, route, 'payload.js')
|
||||||
const payload = await window.__NUXT_IMPORT__(route, src)
|
const payload = await window.__NUXT_IMPORT__(route, src)
|
||||||
this.setPagePayload(payload)
|
this.setPagePayload(payload)
|
||||||
return payload
|
return payload
|
||||||
|
@ -805,7 +805,7 @@ async function mountApp (__app) {
|
|||||||
|
|
||||||
<% if (isFullStatic) { %>
|
<% if (isFullStatic) { %>
|
||||||
// Load page chunk
|
// Load page chunk
|
||||||
if (!NUXT.data && !NUXT.spa) {
|
if (!NUXT.data && NUXT.serverRendered) {
|
||||||
try {
|
try {
|
||||||
const payload = await _app.fetchPayload(_app.context.route.path)
|
const payload = await _app.fetchPayload(_app.context.route.path)
|
||||||
Object.assign(NUXT, payload)
|
Object.assign(NUXT, payload)
|
||||||
|
@ -152,12 +152,9 @@ export default class SPARenderer extends BaseRenderer {
|
|||||||
// Serialize state (runtime config)
|
// Serialize state (runtime config)
|
||||||
let APP = `${meta.BODY_SCRIPTS_PREPEND}<div id="${this.serverContext.globals.id}">${this.serverContext.resources.loadingHTML}</div>${meta.BODY_SCRIPTS}`
|
let APP = `${meta.BODY_SCRIPTS_PREPEND}<div id="${this.serverContext.globals.id}">${this.serverContext.resources.loadingHTML}</div>${meta.BODY_SCRIPTS}`
|
||||||
|
|
||||||
if (renderContext.staticAssetsBase) {
|
|
||||||
APP += `<script>window.__NUXT_STATIC__='${renderContext.staticAssetsBase}'</script>`
|
|
||||||
}
|
|
||||||
APP += `<script>window.${this.serverContext.globals.context}=${devalue({
|
APP += `<script>window.${this.serverContext.globals.context}=${devalue({
|
||||||
config: renderContext.runtimeConfig.public,
|
config: renderContext.runtimeConfig.public,
|
||||||
spa: true
|
staticAssetsBase: renderContext.staticAssetsBase
|
||||||
})}</script>`
|
})}</script>`
|
||||||
|
|
||||||
// Prepare template params
|
// Prepare template params
|
||||||
|
@ -168,8 +168,10 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
const { data, fetch, mutations, ...state } = nuxt
|
const { data, fetch, mutations, ...state } = nuxt
|
||||||
|
|
||||||
// Initial state
|
// Initial state
|
||||||
const nuxtStaticScript = `window.__NUXT_STATIC__='${staticAssetsBase}';`
|
const stateScript = `window.${this.serverContext.globals.context}=${devalue({
|
||||||
const stateScript = `window.${this.serverContext.globals.context}=${devalue(state)};`
|
staticAssetsBase,
|
||||||
|
...state
|
||||||
|
})};`
|
||||||
|
|
||||||
// Make chunk for initial state > 10 KB
|
// Make chunk for initial state > 10 KB
|
||||||
const stateScriptKb = (stateScript.length * 4 /* utf8 */) / 100
|
const stateScriptKb = (stateScript.length * 4 /* utf8 */) / 100
|
||||||
@ -177,11 +179,10 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
const statePath = urlJoin(url, 'state.js')
|
const statePath = urlJoin(url, 'state.js')
|
||||||
const stateUrl = urlJoin(staticAssetsBase, statePath)
|
const stateUrl = urlJoin(staticAssetsBase, statePath)
|
||||||
staticAssets.push({ path: statePath, src: stateScript })
|
staticAssets.push({ path: statePath, src: stateScript })
|
||||||
APP += `<script defer>${nuxtStaticScript}</script>`
|
|
||||||
APP += `<script defer src="${staticAssetsBase}${statePath}"></script>`
|
APP += `<script defer src="${staticAssetsBase}${statePath}"></script>`
|
||||||
preloadScripts.push(stateUrl)
|
preloadScripts.push(stateUrl)
|
||||||
} else {
|
} else {
|
||||||
APP += `<script defer>${nuxtStaticScript}${stateScript}</script>`
|
APP += `<script>${stateScript}</script>`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page level payload.js (async loaded for CSR)
|
// Page level payload.js (async loaded for CSR)
|
||||||
|
Loading…
Reference in New Issue
Block a user