mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
init() ~> ready()
This commit is contained in:
parent
d882b1ac77
commit
2576e8795e
@ -61,7 +61,7 @@ if (argv.analyze) {
|
|||||||
|
|
||||||
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
||||||
var nuxt = module.exports = new Nuxt(options)
|
var nuxt = module.exports = new Nuxt(options)
|
||||||
nuxt.init()
|
nuxt.ready()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('[nuxt] Building done') // eslint-disable-line no-console
|
console.log('[nuxt] Building done') // eslint-disable-line no-console
|
||||||
})
|
})
|
||||||
|
@ -31,7 +31,7 @@ export default class Generator extends Tapable {
|
|||||||
let distNuxtPath = join(distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
|
let distNuxtPath = join(distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
|
||||||
|
|
||||||
// Wait for nuxt be ready
|
// Wait for nuxt be ready
|
||||||
await this.nuxt.init()
|
await this.nuxt.ready()
|
||||||
|
|
||||||
// Clean destination folder
|
// Clean destination folder
|
||||||
await remove(distPath)
|
await remove(distPath)
|
||||||
|
@ -36,12 +36,12 @@ export default class Nuxt extends Tapable {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this._init = this.init().catch(this.errorHandler)
|
this._ready = this.ready().catch(this.errorHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
async init () {
|
async ready () {
|
||||||
if (this._init) {
|
if (this._ready) {
|
||||||
return this._init
|
return this._ready
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for all components to be ready
|
// Wait for all components to be ready
|
||||||
|
@ -41,19 +41,19 @@ export default class Renderer extends Tapable {
|
|||||||
|
|
||||||
if (nuxt.initialized) {
|
if (nuxt.initialized) {
|
||||||
// If nuxt already initialized
|
// If nuxt already initialized
|
||||||
this._init = this.init().catch(this.nuxt.errorHandler)
|
this._ready = this.ready().catch(this.nuxt.errorHandler)
|
||||||
} else {
|
} else {
|
||||||
// Wait for hook
|
// Wait for hook
|
||||||
this.nuxt.plugin('afterInit', () => {
|
this.nuxt.plugin('afterInit', () => {
|
||||||
this._init = this.init()
|
this._ready = this.ready()
|
||||||
return this._init
|
return this._ready
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async init () {
|
async ready () {
|
||||||
if (this._init) {
|
if (this._ready) {
|
||||||
return this._init
|
return this._ready
|
||||||
}
|
}
|
||||||
|
|
||||||
// For serving static/ files to /
|
// For serving static/ files to /
|
||||||
|
@ -10,7 +10,7 @@ class Server {
|
|||||||
// Initialize
|
// Initialize
|
||||||
this.app = connect()
|
this.app = connect()
|
||||||
this.server = http.createServer(this.app)
|
this.server = http.createServer(this.app)
|
||||||
this.nuxt.init()
|
this.nuxt.ready()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Add Middleware
|
// Add Middleware
|
||||||
this.options.serverMiddleware.forEach(m => {
|
this.options.serverMiddleware.forEach(m => {
|
||||||
@ -48,7 +48,7 @@ class Server {
|
|||||||
listen (port, host) {
|
listen (port, host) {
|
||||||
host = host || 'localhost'
|
host = host || 'localhost'
|
||||||
port = port || 3000
|
port = port || 3000
|
||||||
this.nuxt.init()
|
this.nuxt.ready()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.server.listen(port, host, () => {
|
this.server.listen(port, host, () => {
|
||||||
let _host = host === '0.0.0.0' ? 'localhost' : host
|
let _host = host === '0.0.0.0' ? 'localhost' : host
|
||||||
|
@ -15,7 +15,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
dev: true
|
dev: true
|
||||||
}
|
}
|
||||||
nuxt = new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
server = new Nuxt.Server(nuxt)
|
server = new Nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
@ -18,7 +18,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
runBuild: true
|
runBuild: true
|
||||||
}
|
}
|
||||||
nuxt = new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
server = new Nuxt.Server(nuxt)
|
server = new Nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
runBuild: true
|
runBuild: true
|
||||||
}
|
}
|
||||||
nuxt = new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
server = new Nuxt.Server(nuxt)
|
server = new Nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
@ -12,7 +12,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
dev: false,
|
dev: false,
|
||||||
runBuild: true
|
runBuild: true
|
||||||
})
|
})
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Check .nuxt/router.js', t => {
|
test('Check .nuxt/router.js', t => {
|
||||||
|
@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
runBuild: true
|
runBuild: true
|
||||||
}
|
}
|
||||||
nuxt = new Nuxt(options)
|
nuxt = new Nuxt(options)
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
server = new Nuxt.Server(nuxt)
|
server = new Nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
@ -15,8 +15,8 @@ test.serial('Nuxt.js Instance', async t => {
|
|||||||
t.is(nuxt.options.dev, true)
|
t.is(nuxt.options.dev, true)
|
||||||
t.is(typeof nuxt.generate, 'function')
|
t.is(typeof nuxt.generate, 'function')
|
||||||
t.is(typeof nuxt._init.then, 'function')
|
t.is(typeof nuxt._init.then, 'function')
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
t.is(nuxt.initialized, true)
|
t.is(nuxt.readyialized, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test.serial('Fail to build when no pages/ directory but is in the parent', t => {
|
test.serial('Fail to build when no pages/ directory but is in the parent', t => {
|
||||||
@ -25,7 +25,7 @@ test.serial('Fail to build when no pages/ directory but is in the parent', t =>
|
|||||||
runBuild: true,
|
runBuild: true,
|
||||||
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
|
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
|
||||||
})
|
})
|
||||||
return nuxt.init().catch(err => {
|
return nuxt.ready().catch(err => {
|
||||||
let s = String(err)
|
let s = String(err)
|
||||||
t.true(s.includes('No `pages` directory found'))
|
t.true(s.includes('No `pages` directory found'))
|
||||||
t.true(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?'))
|
t.true(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?'))
|
||||||
@ -38,7 +38,7 @@ test.serial('Fail to build when no pages/ directory', t => {
|
|||||||
runBuild: true,
|
runBuild: true,
|
||||||
rootDir: resolve(__dirname)
|
rootDir: resolve(__dirname)
|
||||||
})
|
})
|
||||||
return nuxt.init().catch(err => {
|
return nuxt.ready().catch(err => {
|
||||||
let s = String(err)
|
let s = String(err)
|
||||||
t.true(s.includes('Couldn\'t find a `pages` directory'))
|
t.true(s.includes('Couldn\'t find a `pages` directory'))
|
||||||
t.true(s.includes('Please create one under the project root'))
|
t.true(s.includes('Please create one under the project root'))
|
||||||
|
@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
config.dev = false
|
config.dev = false
|
||||||
config.runBuild = true
|
config.runBuild = true
|
||||||
nuxt = new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
server = new Nuxt.Server(nuxt)
|
server = new Nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
|
@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => {
|
|||||||
config.dev = false
|
config.dev = false
|
||||||
config.runBuild = true
|
config.runBuild = true
|
||||||
nuxt = new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
server = new Nuxt.Server(nuxt)
|
server = new Nuxt.Server(nuxt)
|
||||||
server.listen(port, 'localhost')
|
server.listen(port, 'localhost')
|
||||||
})
|
})
|
||||||
@ -113,5 +113,5 @@ test.after('Should be able to start Nuxt with build done', async t => {
|
|||||||
config.dev = false
|
config.dev = false
|
||||||
config.runBuild = true
|
config.runBuild = true
|
||||||
nuxt = new Nuxt(config)
|
nuxt = new Nuxt(config)
|
||||||
await nuxt.init()
|
await nuxt.ready()
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user