update build

This commit is contained in:
Sébastien Chopin 2016-12-07 19:01:46 +01:00
parent 401930450c
commit 648033f077
2 changed files with 14 additions and 14 deletions

View File

@ -9,6 +9,7 @@ const { resolve } = require('path')
const rootDir = resolve(process.argv.slice(2)[0] || '.') const rootDir = resolve(process.argv.slice(2)[0] || '.')
const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js') const nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
let options = {} let options = {}
if (fs.existsSync(nuxtConfigFile)) { if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile) options = require(nuxtConfigFile)
@ -16,12 +17,12 @@ if (fs.existsSync(nuxtConfigFile)) {
if (typeof options.rootDir !== 'string') { if (typeof options.rootDir !== 'string') {
options.rootDir = rootDir options.rootDir = rootDir
} }
options.dev = false // Create production build when calling `nuxt build` options.dev = false // Create production build when calling `nuxt build`
console.log('[nuxt] Building...') console.log('[nuxt] Building...')
new Nuxt(options) const nuxt = new Nuxt(options)
.then((nuxt) => { nuxt.build()
.then(() => {
console.log('[nuxt] Building done') console.log('[nuxt] Building done')
}) })
.catch((err) => { .catch((err) => {

View File

@ -70,26 +70,24 @@ const defaultsPostcss = [
}) })
] ]
module.exports = function * () { exports.options = function () {
// Defaults build options // Defaults build options
let extraDefaults = {} let extraDefaults = {}
if (this.options.build && !Array.isArray(this.options.build.loaders)) extraDefaults.loaders = defaultsLoaders 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 if (this.options.build && !Array.isArray(this.options.build.postcss)) extraDefaults.postcss = defaultsPostcss
this.options.build = _.defaultsDeep(this.options.build, defaults, extraDefaults) this.options.build = _.defaultsDeep(this.options.build, defaults, extraDefaults)
if (!this.options._build && !this.options._renderer) { // Production, create server-renderer
return Promise.resolve() if (!this.dev) {
}
if (!this.options._build) {
const serverConfig = getWebpackServerConfig.call(this) const serverConfig = getWebpackServerConfig.call(this)
const bundlePath = join(serverConfig.output.path, serverConfig.output.filename) const bundlePath = join(serverConfig.output.path, serverConfig.output.filename)
if (!fs.existsSync(bundlePath)) { if (fs.existsSync(bundlePath)) {
console.error('> No build files found, please run `nuxt build` before launching `nuxt start`') const bundle = fs.readFileSync(bundlePath, 'utf8')
process.exit(1) 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 ** Check if pages dir exists and warn if not
*/ */
@ -135,6 +133,7 @@ module.exports = function * () {
webpackRunServer.call(this) webpackRunServer.call(this)
] ]
} }
return this
} }
function * generateRoutesAndFiles () { function * generateRoutesAndFiles () {