mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25: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.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer)
|
||||
|
||||
// Default Show Open if Nuxt is not listening
|
||||
this.showOpen = () => {}
|
||||
|
||||
this._ready = this.ready().catch(this.errorHandler)
|
||||
}
|
||||
|
||||
@ -49,6 +52,13 @@ export default class Nuxt extends Tapable {
|
||||
}
|
||||
|
||||
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) => {
|
||||
const server = this.renderer.app.listen({ port, host, exclusive: false }, err => {
|
||||
/* istanbul ignore if */
|
||||
@ -56,11 +66,6 @@ export default class Nuxt extends Tapable {
|
||||
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
|
||||
this.plugin('close', () => new Promise((resolve, reject) => {
|
||||
// Destroy server by forcing every connection to be closed
|
||||
|
@ -124,22 +124,41 @@ export default class Renderer extends Tapable {
|
||||
|
||||
get isReady () {
|
||||
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 () {
|
||||
// Create Meta Renderer
|
||||
this.metaRenderer = new MetaRenderer(this.nuxt, this)
|
||||
|
||||
// Check if SSR is disabled
|
||||
if (this.noSSR) {
|
||||
// Ensure resources are available
|
||||
if (!this.isResourcesAvailable) {
|
||||
return
|
||||
}
|
||||
|
||||
// If resources are not yet provided
|
||||
if (!this.resources.serverBundle || !this.resources.clientManifest) {
|
||||
// Create Meta Renderer
|
||||
this.metaRenderer = new MetaRenderer(this.nuxt, this)
|
||||
|
||||
// Show Open URL
|
||||
this.nuxt.showOpen()
|
||||
|
||||
// Skip following steps if noSSR mode
|
||||
if (this.noSSR) {
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user