mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
imrpove CLI experience for OPEN url
This commit is contained in:
parent
6c4803a840
commit
a585d8cb35
@ -32,6 +32,9 @@ export default class Nuxt extends Tapable {
|
|||||||
this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
|
this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
|
||||||
this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer)
|
this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer)
|
||||||
|
|
||||||
|
// Default Show Open if Nuxt is not listening
|
||||||
|
this.showOpen = () => {}
|
||||||
|
|
||||||
this._ready = this.ready().catch(this.errorHandler)
|
this._ready = this.ready().catch(this.errorHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +52,13 @@ export default class Nuxt extends Tapable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listen (port = 3000, host = 'localhost') {
|
listen (port = 3000, host = 'localhost') {
|
||||||
|
// Update showOpen
|
||||||
|
this.showOpen = () => {
|
||||||
|
const _host = host === '0.0.0.0' ? 'localhost' : host
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${_host}:${port}\n`))
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const server = this.renderer.app.listen({ port, host, exclusive: false }, err => {
|
const server = this.renderer.app.listen({ port, host, exclusive: false }, err => {
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
@ -56,11 +66,6 @@ export default class Nuxt extends Tapable {
|
|||||||
return reject(err)
|
return reject(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show Open URL
|
|
||||||
let _host = host === '0.0.0.0' ? 'localhost' : host
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('\n' + chalk.bold(chalk.bgGreen.white(' OPEN ') + chalk.green(` http://${_host}:${port}\n`)))
|
|
||||||
|
|
||||||
// Close server on nuxt close
|
// Close server on nuxt close
|
||||||
this.plugin('close', () => new Promise((resolve, reject) => {
|
this.plugin('close', () => new Promise((resolve, reject) => {
|
||||||
// Destroy server by forcing every connection to be closed
|
// Destroy server by forcing every connection to be closed
|
||||||
|
@ -124,22 +124,41 @@ export default class Renderer extends Tapable {
|
|||||||
|
|
||||||
get isReady () {
|
get isReady () {
|
||||||
if (this.noSSR) {
|
if (this.noSSR) {
|
||||||
return this.resources.spaTemplate
|
return Boolean(this.resources.spaTemplate)
|
||||||
}
|
}
|
||||||
return this.bundleRenderer && this.resources.ssrTemplate
|
|
||||||
|
return Boolean(this.bundleRenderer && this.resources.ssrTemplate)
|
||||||
|
}
|
||||||
|
|
||||||
|
get isResourcesAvailable () {
|
||||||
|
// Required for both
|
||||||
|
if (!this.resources.clientManifest) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Required for SPA rendering
|
||||||
|
if (this.noSSR) {
|
||||||
|
return Boolean(this.resources.spaTemplate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Required for bundle renderer
|
||||||
|
return Boolean(this.resources.ssrTemplate && this.resources.serverBundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
createRenderer () {
|
createRenderer () {
|
||||||
// Create Meta Renderer
|
// Ensure resources are available
|
||||||
this.metaRenderer = new MetaRenderer(this.nuxt, this)
|
if (!this.isResourcesAvailable) {
|
||||||
|
|
||||||
// Check if SSR is disabled
|
|
||||||
if (this.noSSR) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If resources are not yet provided
|
// Create Meta Renderer
|
||||||
if (!this.resources.serverBundle || !this.resources.clientManifest) {
|
this.metaRenderer = new MetaRenderer(this.nuxt, this)
|
||||||
|
|
||||||
|
// Show Open URL
|
||||||
|
this.nuxt.showOpen()
|
||||||
|
|
||||||
|
// Skip following steps if noSSR mode
|
||||||
|
if (this.noSSR) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user