mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-20 15:41:11 +00:00
fix: modules called before renderer in production
This commit is contained in:
parent
5682eef2a5
commit
f958801fff
@ -76,8 +76,10 @@ export function options () {
|
||||
if (this.dev && isUrl(this.options.build.publicPath)) {
|
||||
this.options.build.publicPath = defaults.publicPath
|
||||
}
|
||||
}
|
||||
|
||||
export function production () {
|
||||
// Production, create server-renderer
|
||||
if (!this.dev) {
|
||||
webpackStats = {
|
||||
chunks: false,
|
||||
children: false,
|
||||
@ -94,7 +96,6 @@ export function options () {
|
||||
addAppTemplate.call(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function build () {
|
||||
// Avoid calling this method multiple times
|
||||
|
@ -42,6 +42,10 @@ export default async function () {
|
||||
const s = Date.now()
|
||||
let errors = []
|
||||
/*
|
||||
** Wait for modules to be initialized
|
||||
*/
|
||||
await this.ready()
|
||||
/*
|
||||
** Set variables
|
||||
*/
|
||||
this.options.generate = _.defaultsDeep(this.options.generate, defaults)
|
||||
|
@ -19,10 +19,11 @@ class Module {
|
||||
async ready () {
|
||||
if (this.initing) {
|
||||
await this.initing
|
||||
return
|
||||
return this
|
||||
}
|
||||
// Install all modules in sequence
|
||||
await sequence(this.options.modules, this.addModule.bind(this))
|
||||
return this
|
||||
}
|
||||
|
||||
addVendor (vendor) {
|
||||
|
19
lib/nuxt.js
19
lib/nuxt.js
@ -124,20 +124,25 @@ class Nuxt {
|
||||
// Add module integration
|
||||
this.module = new Module(this)
|
||||
// Init nuxt.js
|
||||
this.ready()
|
||||
// Launch build in development but don't wait for him to be finished
|
||||
if (this.dev) {
|
||||
this.build()
|
||||
}
|
||||
this._ready = this.ready()
|
||||
// Return nuxt.js instance
|
||||
return this
|
||||
}
|
||||
|
||||
async ready () {
|
||||
if (this._ready) return this
|
||||
if (this._ready) {
|
||||
await this._ready
|
||||
return this
|
||||
}
|
||||
// Init modules
|
||||
await this.module.ready()
|
||||
this._ready = true
|
||||
// Launch build in development but don't wait for it to be finished
|
||||
if (this.dev) {
|
||||
this.build()
|
||||
} else {
|
||||
build.production.call(this)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
close (callback) {
|
||||
|
@ -11,6 +11,9 @@ debug.color = 4
|
||||
setAnsiColors(ansiHTML)
|
||||
|
||||
export async function render (req, res) {
|
||||
// Wait for nuxt.js to be ready
|
||||
await this.ready()
|
||||
// Check if project is built for production
|
||||
if (!this.renderer && !this.dev) {
|
||||
console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') // eslint-disable-line no-console
|
||||
process.exit(1)
|
||||
@ -23,8 +26,6 @@ export async function render (req, res) {
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
// Wait for nuxt.js to be ready
|
||||
await this.ready()
|
||||
// Get context
|
||||
const context = getContext(req, res)
|
||||
res.statusCode = 200
|
||||
|
Loading…
Reference in New Issue
Block a user