Nuxt/bin/nuxt-build

64 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env node
2016-11-10 14:24:22 +00:00
// Show logs
process.env.DEBUG = 'nuxt:*'
2016-12-09 18:40:59 +00:00
var fs = require('fs')
2017-01-23 16:55:39 +00:00
var without = require('lodash').without
2016-12-09 18:40:59 +00:00
var Nuxt = require('../')
var resolve = require('path').resolve
2017-01-23 16:55:39 +00:00
// --analyze option
var analyzeBuild = false
if (process.argv.indexOf('--analyze') !== -1 || process.argv.indexOf('-a') !== -1) {
analyzeBuild = true
process.argv = without(process.argv, '--analyze', '-a')
}
var nuxtConfigFileName = 'nuxt.config.js'
2017-03-15 14:14:16 +00:00
// --config-file option
var indexOfConfig = false
if (process.argv.indexOf('--config-file') !== -1) {
indexOfConfig = process.argv.indexOf('--config-file')
} else if (process.argv.indexOf('-c') !== -1) {
indexOfConfig = process.argv.indexOf('-c')
}
if (indexOfConfig !== false) {
nuxtConfigFileName = process.argv.slice(indexOfConfig)[1]
process.argv = without(process.argv, '--config-file', '-c', nuxtConfigFileName)
}
2017-03-15 14:14:16 +00:00
// Root directory parameter
2016-12-09 18:40:59 +00:00
var rootDir = resolve(process.argv.slice(2)[0] || '.')
var nuxtConfigFilePath = resolve(rootDir, nuxtConfigFileName)
2016-12-07 18:01:46 +00:00
2016-12-09 18:40:59 +00:00
var options = {}
if (fs.existsSync(nuxtConfigFilePath)) {
options = require(nuxtConfigFilePath)
} else {
console.log(`Could not locate ${nuxtConfigFilePath}`) // eslint-disable-line no-console
}
if (typeof options.rootDir !== 'string') {
options.rootDir = rootDir
}
options.dev = false // Create production build when calling `nuxt build`
2017-01-23 16:55:39 +00:00
options.build = options.build || {}
2017-01-24 19:25:56 +00:00
if (analyzeBuild) {
options.build.analyze = analyzeBuild
}
2017-01-23 16:55:39 +00:00
2016-12-08 15:41:20 +00:00
console.log('[nuxt] Building...') // eslint-disable-line no-console
var nuxt = module.exports = new Nuxt(options)
nuxt.build()
.then(() => {
console.log('[nuxt] Building done') // eslint-disable-line no-console
})
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})