mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
45 lines
1.1 KiB
JavaScript
Executable File
45 lines
1.1 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 rootDir = resolve(process.argv.slice(2)[0] || '.')
|
|
var nuxtConfigFile = resolve(rootDir, 'nuxt.config.js')
|
|
|
|
var options = {}
|
|
if (fs.existsSync(nuxtConfigFile)) {
|
|
options = require(nuxtConfigFile)
|
|
}
|
|
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)
|
|
})
|