nuxt-start: throw error if nuxt build not called

This commit is contained in:
Pooya Parsa 2017-06-16 18:34:40 +04:30
parent faa8db4701
commit 9d1765ae91

View File

@ -3,7 +3,7 @@
const fs = require('fs')
const parseArgs = require('minimist')
const { Nuxt, Server } = require('../')
const resolve = require('path').resolve
const { join, resolve } = require('path')
const argv = parseArgs(process.argv.slice(2), {
alias: {
@ -55,6 +55,13 @@ if (typeof options.rootDir !== 'string') {
}
options.dev = false // Force production mode (no webpack middleware called)
// Check if project is built for production
const distDir = join(options.rootDir, options.buildDir || '.nuxt', 'dist' )
if (!fs.existsSync(join(distDir,'server-bundle.json'))) {
console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') // eslint-disable-line no-console
process.exit(1)
}
const nuxt = new Nuxt(options)
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