mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
feat: allow disabling loading-screen (#6272)
This commit is contained in:
parent
2091233a6d
commit
f20d932c4d
@ -3,11 +3,6 @@ import env from 'std-env'
|
|||||||
export default () => ({
|
export default () => ({
|
||||||
quiet: Boolean(env.ci || env.test),
|
quiet: Boolean(env.ci || env.test),
|
||||||
analyze: false,
|
analyze: false,
|
||||||
indicator: {
|
|
||||||
position: 'bottom-right',
|
|
||||||
backgroundColor: '#2E495E',
|
|
||||||
color: '#00C48D'
|
|
||||||
},
|
|
||||||
profile: process.argv.includes('--profile'),
|
profile: process.argv.includes('--profile'),
|
||||||
extractCSS: false,
|
extractCSS: false,
|
||||||
crossorigin: undefined,
|
crossorigin: undefined,
|
||||||
@ -121,5 +116,13 @@ export default () => ({
|
|||||||
friendlyErrors: true,
|
friendlyErrors: true,
|
||||||
additionalExtensions: [],
|
additionalExtensions: [],
|
||||||
warningIgnoreFilters: [],
|
warningIgnoreFilters: [],
|
||||||
followSymlinks: false
|
|
||||||
|
followSymlinks: false,
|
||||||
|
|
||||||
|
loadingScreen: {},
|
||||||
|
indicator: {
|
||||||
|
position: 'bottom-right',
|
||||||
|
backgroundColor: '#2E495E',
|
||||||
|
color: '#00C48D'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
@ -404,13 +404,19 @@ export function getNuxtConfig (_options) {
|
|||||||
bundleRenderer.runInNewContext = options.dev
|
bundleRenderer.runInNewContext = options.dev
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add loading screen
|
// Loading screen
|
||||||
if (options.dev) {
|
// disable for production and programmatic users
|
||||||
options.buildModules.push('@nuxt/loading-screen')
|
if (!options.dev || !options._cli) {
|
||||||
// Disable build indicator for programmatic users
|
options.build.loadingScreen = false
|
||||||
if (!options._cli) {
|
}
|
||||||
options.build.indicator = false
|
// Add loading-screen module
|
||||||
}
|
if (options.build.loadingScreen) {
|
||||||
|
options.buildModules.push(['@nuxt/loading-screen', options.build.loadingScreen])
|
||||||
|
}
|
||||||
|
|
||||||
|
// When loadingScreen is disabled we should also disable build indicator
|
||||||
|
if (!options.build.loadingScreen) {
|
||||||
|
options.build.indicator = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const { timing } = options.server
|
const { timing } = options.server
|
||||||
|
@ -57,11 +57,7 @@ Object {
|
|||||||
"useShortDoctype": true,
|
"useShortDoctype": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"indicator": Object {
|
"indicator": false,
|
||||||
"backgroundColor": "#2E495E",
|
|
||||||
"color": "#00C48D",
|
|
||||||
"position": "bottom-right",
|
|
||||||
},
|
|
||||||
"loaders": Object {
|
"loaders": Object {
|
||||||
"css": Object {
|
"css": Object {
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
@ -108,6 +104,7 @@ Object {
|
|||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"loadingScreen": false,
|
||||||
"optimization": Object {
|
"optimization": Object {
|
||||||
"minimize": true,
|
"minimize": true,
|
||||||
"minimizer": undefined,
|
"minimizer": undefined,
|
||||||
|
@ -82,6 +82,7 @@ Object {
|
|||||||
},
|
},
|
||||||
"vueStyle": Object {},
|
"vueStyle": Object {},
|
||||||
},
|
},
|
||||||
|
"loadingScreen": Object {},
|
||||||
"optimization": Object {
|
"optimization": Object {
|
||||||
"minimize": undefined,
|
"minimize": undefined,
|
||||||
"minimizer": undefined,
|
"minimizer": undefined,
|
||||||
@ -437,6 +438,7 @@ Object {
|
|||||||
},
|
},
|
||||||
"vueStyle": Object {},
|
"vueStyle": Object {},
|
||||||
},
|
},
|
||||||
|
"loadingScreen": Object {},
|
||||||
"optimization": Object {
|
"optimization": Object {
|
||||||
"minimize": undefined,
|
"minimize": undefined,
|
||||||
"minimizer": undefined,
|
"minimizer": undefined,
|
||||||
|
@ -2,7 +2,7 @@ import path from 'path'
|
|||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import template from 'lodash/template'
|
import template from 'lodash/template'
|
||||||
import { isModernRequest } from '@nuxt/utils'
|
import { isModernRequest, waitFor } from '@nuxt/utils'
|
||||||
|
|
||||||
import SPARenderer from './renderers/spa'
|
import SPARenderer from './renderers/spa'
|
||||||
import SSRRenderer from './renderers/ssr'
|
import SSRRenderer from './renderers/ssr'
|
||||||
@ -238,30 +238,35 @@ export default class VueRenderer {
|
|||||||
return renderer.render(renderContext)
|
return renderer.render(renderContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderRoute (url, renderContext = {}, _retried) {
|
async renderRoute (url, renderContext = {}, _retried = 0) {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!this.isReady) {
|
if (!this.isReady) {
|
||||||
// Production
|
// Fall-back to loading-screen if enabled
|
||||||
if (!this.options.dev) {
|
if (this.options.build.loadingScreen) {
|
||||||
if (!_retried && ['loading', 'created'].includes(this._state)) {
|
// Tell nuxt middleware to use `server:nuxt:renderLoading hook
|
||||||
await this.ready()
|
return false
|
||||||
return this.renderRoute(url, renderContext, true)
|
}
|
||||||
}
|
|
||||||
switch (this._state) {
|
// Retry
|
||||||
case 'created':
|
const retryLimit = this.options.dev ? 60 : 3
|
||||||
throw new Error('Renderer ready() is not called! Please ensure `nuxt.ready()` is called and awaited.')
|
if (_retried < retryLimit && this._state !== 'error') {
|
||||||
case 'loading':
|
await this.ready().then(() => waitFor(1000))
|
||||||
throw new Error('Renderer is loading.')
|
return this.renderRoute(url, renderContext, _retried + 1)
|
||||||
case 'error':
|
}
|
||||||
throw this._error
|
|
||||||
case 'ready':
|
// Throw Error
|
||||||
throw new Error(`Renderer is loaded but not all resources are available! Please check ${this.distPath} existence.`)
|
switch (this._state) {
|
||||||
default:
|
case 'created':
|
||||||
throw new Error('Renderer is in unknown state!')
|
throw new Error('Renderer ready() is not called! Please ensure `nuxt.ready()` is called and awaited.')
|
||||||
}
|
case 'loading':
|
||||||
|
throw new Error('Renderer is loading.')
|
||||||
|
case 'error':
|
||||||
|
throw this._error
|
||||||
|
case 'ready':
|
||||||
|
throw new Error(`Renderer resources are not loaded! Please check possible console errors and ensure dist (${this.distPath}) exists.`)
|
||||||
|
default:
|
||||||
|
throw new Error('Renderer is in unknown state!')
|
||||||
}
|
}
|
||||||
// Tell nuxt middleware to render UI
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log rendered url
|
// Log rendered url
|
||||||
|
Loading…
Reference in New Issue
Block a user