mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
feat: enhance tapables usage
This commit is contained in:
parent
e6987d62f0
commit
b5ca6b7975
@ -43,9 +43,6 @@ export default class Builder extends Tapable {
|
||||
// Helper to resolve build paths
|
||||
this.relativeToBuild = (...args) => relativeTo(this.options.buildDir, ...args)
|
||||
|
||||
// Call builder plugin on parent nuxt to notify all modules of builder existence
|
||||
this.nuxt.applyPluginsAsync('builder', this).catch(this.nuxt.errorHandler)
|
||||
|
||||
this._buildStatus = STATUS.INITIAL
|
||||
}
|
||||
|
||||
@ -77,7 +74,7 @@ export default class Builder extends Tapable {
|
||||
// Wait for nuxt ready
|
||||
await this.nuxt.ready()
|
||||
|
||||
await this.applyPluginsAsync('build', this)
|
||||
await this.nuxt.applyPluginsAsync('build', this)
|
||||
|
||||
// Check if pages dir exists and warn if not
|
||||
this._nuxtPages = typeof this.options.build.createRoutes !== 'function'
|
||||
|
@ -21,9 +21,6 @@ export default class Generator extends Tapable {
|
||||
this.srcBuiltPath = resolve(this.options.buildDir, 'dist')
|
||||
this.distPath = resolve(this.options.rootDir, this.options.generate.dir)
|
||||
this.distNuxtPath = join(this.distPath, (isUrl(this.options.build.publicPath) ? '' : this.options.build.publicPath))
|
||||
|
||||
// Call generator plugin on parent nuxt to notify all modules of generator existence
|
||||
this.nuxt.applyPluginsAsync('generator', this).catch(this.nuxt.errorHandler)
|
||||
}
|
||||
|
||||
async generate ({ build = true, init = true } = {}) {
|
||||
@ -38,7 +35,7 @@ export default class Generator extends Tapable {
|
||||
await this.builder.build()
|
||||
}
|
||||
|
||||
await this.applyPluginsAsync('beforeGenerate', this)
|
||||
await this.nuxt.applyPluginsAsync('generate', this)
|
||||
|
||||
// Initialize dist directory
|
||||
if (init) {
|
||||
|
@ -14,11 +14,11 @@ export default class ModuleContainer extends Tapable {
|
||||
this.nuxt = nuxt
|
||||
this.options = nuxt.options
|
||||
this.requiredModules = []
|
||||
}
|
||||
|
||||
this.nuxt.plugin('beforeInit', async () => {
|
||||
await sequence(this.options.modules, this.addModule.bind(this))
|
||||
await this.applyPluginsAsync('ready', this)
|
||||
})
|
||||
async _ready () {
|
||||
await sequence(this.options.modules, this.addModule.bind(this))
|
||||
await this.nuxt.applyPluginsAsync('module', this)
|
||||
}
|
||||
|
||||
addVendor (vendor) {
|
||||
|
@ -28,7 +28,7 @@ export default class Nuxt extends Tapable {
|
||||
this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
|
||||
this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer)
|
||||
|
||||
this._ready = this.ready()
|
||||
this._ready = this.ready().catch(this.errorHandler)
|
||||
}
|
||||
|
||||
async ready () {
|
||||
@ -36,10 +36,9 @@ export default class Nuxt extends Tapable {
|
||||
return this._ready
|
||||
}
|
||||
|
||||
// Wait for all components to be ready
|
||||
await this.applyPluginsAsync('beforeInit') // 1- Modules
|
||||
await this.applyPluginsAsync('init') // 2- Builder
|
||||
await this.applyPluginsAsync('afterInit') // 3- Renderer
|
||||
await this.moduleContainer._ready()
|
||||
await this.applyPluginsAsync('ready')
|
||||
await this.renderer._ready()
|
||||
|
||||
this.initialized = true
|
||||
return this
|
||||
@ -73,6 +72,7 @@ export default class Nuxt extends Tapable {
|
||||
|
||||
resolve()
|
||||
})
|
||||
|
||||
// Add server.destroy(cb) method
|
||||
enableDestroy(server)
|
||||
})
|
||||
|
@ -50,27 +50,9 @@ export default class Renderer extends Tapable {
|
||||
// Bind middleware to this context
|
||||
this.nuxtMiddleware = this.nuxtMiddleware.bind(this)
|
||||
this.errorMiddleware = this.errorMiddleware.bind(this)
|
||||
|
||||
// Initialize
|
||||
/* istanbul ignore if */
|
||||
if (nuxt.initialized) {
|
||||
// If nuxt already initialized
|
||||
this._ready = this.ready().catch(this.nuxt.errorHandler)
|
||||
} else {
|
||||
// Wait for hook
|
||||
this.nuxt.plugin('afterInit', () => {
|
||||
this._ready = this.ready()
|
||||
return this._ready
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async ready () {
|
||||
/* istanbul ignore if */
|
||||
if (this._ready) {
|
||||
return this._ready
|
||||
}
|
||||
|
||||
async _ready () {
|
||||
// Setup all middleWare
|
||||
await this.setupMiddleware()
|
||||
|
||||
@ -85,7 +67,7 @@ export default class Renderer extends Tapable {
|
||||
await this.loadResources()
|
||||
}
|
||||
|
||||
return this
|
||||
await this.nuxt.applyPluginsAsync('renderer', this)
|
||||
}
|
||||
|
||||
async loadResources (_fs = fs) {
|
||||
|
Loading…
Reference in New Issue
Block a user