mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
64 lines
1.7 KiB
JavaScript
Executable File
64 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
// Show logs
|
|
process.env.DEBUG = 'nuxt:*'
|
|
|
|
var fs = require('fs')
|
|
var without = require('lodash').without
|
|
var Nuxt = require('../')
|
|
var resolve = require('path').resolve
|
|
|
|
// --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'
|
|
|
|
// --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)
|
|
}
|
|
|
|
// Root directory parameter
|
|
var rootDir = resolve(process.argv.slice(2)[0] || '.')
|
|
var nuxtConfigFilePath = resolve(rootDir, nuxtConfigFileName)
|
|
|
|
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`
|
|
|
|
options.build = options.build || {}
|
|
if (analyzeBuild) {
|
|
options.build.analyze = analyzeBuild
|
|
}
|
|
|
|
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
|
var nuxt = 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)
|
|
})
|