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