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 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) => {

View File

@ -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)
}
const bundle = yield readFile(bundlePath, 'utf8')
if (fs.existsSync(bundlePath)) {
const bundle = fs.readFileSync(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 () {