mirror of
https://github.com/nuxt/nuxt.git
synced 2025-03-03 19:24:35 +00:00
fix(nuxt-dev): successful rebuild if nuxt.config.js has problems
This commit is contained in:
parent
8cf56284ac
commit
38b71cbe04
33
bin/nuxt-dev
33
bin/nuxt-dev
@ -84,24 +84,41 @@ function startDev(oldNuxt) {
|
|||||||
const port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
const port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
|
||||||
const host = argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
|
const host = argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
|
||||||
|
|
||||||
|
// Error handler
|
||||||
|
const onError = (err, nuxt) => {
|
||||||
|
debug('Error while reloading [nuxt.config.js]', err)
|
||||||
|
return Promise.resolve(nuxt) // Wait for next reload
|
||||||
|
}
|
||||||
|
|
||||||
// Load options
|
// Load options
|
||||||
let options = {}
|
let options = {}
|
||||||
try {
|
try {
|
||||||
options = loadNuxtConfig()
|
options = loadNuxtConfig()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
return onError(err, oldNuxt)
|
||||||
return // Wait for next reload
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create nuxt and builder instance
|
// Create nuxt and builder instance
|
||||||
const nuxt = new Nuxt(options)
|
let nuxt
|
||||||
const builder = new Builder(nuxt)
|
let builder
|
||||||
|
try {
|
||||||
|
nuxt = new Nuxt(options)
|
||||||
|
builder = new Builder(nuxt)
|
||||||
|
} catch (err) {
|
||||||
|
return onError(err, nuxt || oldNuxt)
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => builder.build()) // 1- Start build
|
// Start build
|
||||||
.then(() => oldNuxt ? oldNuxt.close() : Promise.resolve()) // 2- Close old nuxt after successful build
|
.then(() => builder.build())
|
||||||
.then(() => nuxt.listen(port, host)) // 3- Start listening
|
// Close old nuxt after successful build
|
||||||
.then(() => nuxt) // 4- Pass new nuxt to watch chain
|
.then(() => oldNuxt ? oldNuxt.close() : Promise.resolve())
|
||||||
|
// Start listening
|
||||||
|
.then(() => nuxt.listen(port, host))
|
||||||
|
// Pass new nuxt to watch chain
|
||||||
|
.then(() => nuxt)
|
||||||
|
// Handle errors
|
||||||
|
.catch((err) => onError(err, nuxt))
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadNuxtConfig() {
|
function loadNuxtConfig() {
|
||||||
|
Loading…
Reference in New Issue
Block a user