mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +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) {
|
||||
route = (route.replace(/\/+$/, '') || '/').split('?')[0]
|
||||
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)
|
||||
this.setPagePayload(payload)
|
||||
return payload
|
||||
|
@ -805,7 +805,7 @@ async function mountApp (__app) {
|
||||
|
||||
<% if (isFullStatic) { %>
|
||||
// Load page chunk
|
||||
if (!NUXT.data && !NUXT.spa) {
|
||||
if (!NUXT.data && NUXT.serverRendered) {
|
||||
try {
|
||||
const payload = await _app.fetchPayload(_app.context.route.path)
|
||||
Object.assign(NUXT, payload)
|
||||
|
@ -152,12 +152,9 @@ export default class SPARenderer extends BaseRenderer {
|
||||
// Serialize state (runtime config)
|
||||
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({
|
||||
config: renderContext.runtimeConfig.public,
|
||||
spa: true
|
||||
staticAssetsBase: renderContext.staticAssetsBase
|
||||
})}</script>`
|
||||
|
||||
// Prepare template params
|
||||
|
@ -168,8 +168,10 @@ export default class SSRRenderer extends BaseRenderer {
|
||||
const { data, fetch, mutations, ...state } = nuxt
|
||||
|
||||
// Initial state
|
||||
const nuxtStaticScript = `window.__NUXT_STATIC__='${staticAssetsBase}';`
|
||||
const stateScript = `window.${this.serverContext.globals.context}=${devalue(state)};`
|
||||
const stateScript = `window.${this.serverContext.globals.context}=${devalue({
|
||||
staticAssetsBase,
|
||||
...state
|
||||
})};`
|
||||
|
||||
// Make chunk for initial state > 10 KB
|
||||
const stateScriptKb = (stateScript.length * 4 /* utf8 */) / 100
|
||||
@ -177,11 +179,10 @@ export default class SSRRenderer extends BaseRenderer {
|
||||
const statePath = urlJoin(url, 'state.js')
|
||||
const stateUrl = urlJoin(staticAssetsBase, statePath)
|
||||
staticAssets.push({ path: statePath, src: stateScript })
|
||||
APP += `<script defer>${nuxtStaticScript}</script>`
|
||||
APP += `<script defer src="${staticAssetsBase}${statePath}"></script>`
|
||||
preloadScripts.push(stateUrl)
|
||||
} else {
|
||||
APP += `<script defer>${nuxtStaticScript}${stateScript}</script>`
|
||||
APP += `<script>${stateScript}</script>`
|
||||
}
|
||||
|
||||
// Page level payload.js (async loaded for CSR)
|
||||
|
Loading…
Reference in New Issue
Block a user