mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Nuxt.* Components
This commit is contained in:
parent
754fcc2f59
commit
a14819ca88
38
lib/nuxt.js
38
lib/nuxt.js
@ -2,15 +2,16 @@ import _ from 'lodash'
|
||||
import compression from 'compression'
|
||||
import fs from 'fs-extra'
|
||||
import pify from 'pify'
|
||||
import Server from './server'
|
||||
import ModuleContainer from './module-container'
|
||||
import Builder from './builder'
|
||||
import Renderer from './renderer'
|
||||
import Generate from './generate'
|
||||
import serveStatic from 'serve-static'
|
||||
import { resolve, join } from 'path'
|
||||
import defaults from './defaults'
|
||||
import * as Utils from './utils'
|
||||
import Tapable from 'tapable'
|
||||
import Builder from './builder'
|
||||
import Renderer from './renderer'
|
||||
import Generator from './generator'
|
||||
import ModuleContainer from './module-container'
|
||||
import Server from './server'
|
||||
import Defaults from './defaults'
|
||||
|
||||
export default class Nuxt extends Tapable {
|
||||
constructor (options = {}) {
|
||||
@ -31,30 +32,32 @@ export default class Nuxt extends Tapable {
|
||||
}
|
||||
|
||||
// Apply defaults
|
||||
this.options = _.defaultsDeep(options, defaults)
|
||||
this.options = _.defaultsDeep(options, Nuxt.Defaults)
|
||||
|
||||
// Resolve dirs
|
||||
this.options.rootDir = (typeof options.rootDir === 'string' && options.rootDir ? options.rootDir : process.cwd())
|
||||
this.options.srcDir = (typeof options.srcDir === 'string' && options.srcDir ? resolve(options.rootDir, options.srcDir) : this.options.rootDir)
|
||||
this.options.buildDir = join(this.options.rootDir, options.buildDir)
|
||||
|
||||
this.Server = Server
|
||||
this.componentTasks()
|
||||
|
||||
// Create instance of core components
|
||||
this.builder = new Builder(this)
|
||||
this.renderer = new Renderer(this)
|
||||
this.generate = new Generate(this)
|
||||
this.moduleContainer = new ModuleContainer(this)
|
||||
this.builder = new Nuxt.Builder(this)
|
||||
this.renderer = new Nuxt.Renderer(this)
|
||||
this.generator = new Nuxt.Generator(this)
|
||||
this.moduleContainer = new Nuxt.ModuleContainer(this)
|
||||
|
||||
// Backward compatibility
|
||||
this.render = this.renderer.render.bind(this.renderer)
|
||||
this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
|
||||
this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(this.renderer)
|
||||
this.build = this.ready.bind(this)
|
||||
this.generate = this.generator.generate.bind(this.generator)
|
||||
this.dir = options.rootDir
|
||||
this.srcDir = options.srcDir
|
||||
this.buildDir = options.buildDir
|
||||
this.Server = Nuxt.Server
|
||||
this.Utils = Nuxt.Utils
|
||||
|
||||
// Wait for all core components be ready
|
||||
// eslint-disable-next-line no-console
|
||||
@ -99,8 +102,6 @@ export default class Nuxt extends Tapable {
|
||||
}
|
||||
await this.moduleContainer.ready()
|
||||
await this.builder.ready()
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[nuxt] ready')
|
||||
return this
|
||||
}
|
||||
|
||||
@ -133,3 +134,12 @@ export default class Nuxt extends Tapable {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Add core components to Nuxt class
|
||||
Nuxt.Defaults = Defaults
|
||||
Nuxt.Utils = Utils
|
||||
Nuxt.Renderer = Renderer
|
||||
Nuxt.Builder = Builder
|
||||
Nuxt.ModuleContainer = ModuleContainer
|
||||
Nuxt.Server = Server
|
||||
Nuxt.Generator = Generator
|
||||
|
Loading…
Reference in New Issue
Block a user