diff --git a/bin/nuxt-build b/bin/nuxt-build index fe53759e30..c32dc0221d 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -9,6 +9,7 @@ const { resolve } = require('path') const rootDir = resolve(process.argv.slice(2)[0] || '.') const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js') + let options = {} if (fs.existsSync(nuxtConfigFile)) { options = require(nuxtConfigFile) @@ -16,12 +17,12 @@ if (fs.existsSync(nuxtConfigFile)) { if (typeof options.rootDir !== 'string') { options.rootDir = rootDir } - options.dev = false // Create production build when calling `nuxt build` console.log('[nuxt] Building...') -new Nuxt(options) -.then((nuxt) => { +const nuxt = new Nuxt(options) +nuxt.build() +.then(() => { console.log('[nuxt] Building done') }) .catch((err) => { diff --git a/lib/build/index.js b/lib/build/index.js index 820f276a10..4fa69d3c7b 100644 --- a/lib/build/index.js +++ b/lib/build/index.js @@ -70,26 +70,24 @@ const defaultsPostcss = [ }) ] -module.exports = function * () { +exports.options = function () { // Defaults build options let extraDefaults = {} if (this.options.build && !Array.isArray(this.options.build.loaders)) extraDefaults.loaders = defaultsLoaders if (this.options.build && !Array.isArray(this.options.build.postcss)) extraDefaults.postcss = defaultsPostcss this.options.build = _.defaultsDeep(this.options.build, defaults, extraDefaults) - if (!this.options._build && !this.options._renderer) { - return Promise.resolve() - } - if (!this.options._build) { + // Production, create server-renderer + if (!this.dev) { const serverConfig = getWebpackServerConfig.call(this) const bundlePath = join(serverConfig.output.path, serverConfig.output.filename) - if (!fs.existsSync(bundlePath)) { - console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') - process.exit(1) + if (fs.existsSync(bundlePath)) { + const bundle = fs.readFileSync(bundlePath, 'utf8') + createRenderer.call(this, bundle) } - const bundle = yield readFile(bundlePath, 'utf8') - createRenderer.call(this, bundle) - return Promise.resolve() } +} + +exports.build = function * () { /* ** Check if pages dir exists and warn if not */ @@ -135,6 +133,7 @@ module.exports = function * () { webpackRunServer.call(this) ] } + return this } function * generateRoutesAndFiles () {