mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
04e53b0f9f
* feat: add quite mode for nuxt-build * fix: typoe * fix: better description * revert: level change in options
88 lines
2.1 KiB
JavaScript
Executable File
88 lines
2.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
const parseArgs = require('minimist')
|
|
const consola = require('consola')
|
|
const { Nuxt, Builder, Generator } = require('..')
|
|
const { loadNuxtConfig } = require('./common/utils')
|
|
|
|
const argv = parseArgs(process.argv.slice(2), {
|
|
alias: {
|
|
h: 'help',
|
|
c: 'config-file',
|
|
a: 'analyze',
|
|
s: 'spa',
|
|
u: 'universal',
|
|
q: 'quiet'
|
|
},
|
|
boolean: ['h', 'a', 's', 'u', 'q'],
|
|
string: ['c'],
|
|
default: {
|
|
c: 'nuxt.config.js'
|
|
}
|
|
})
|
|
|
|
if (argv.help) {
|
|
process.stderr.write(`
|
|
Description
|
|
Compiles the application for production deployment
|
|
Usage
|
|
$ nuxt build <dir>
|
|
Options
|
|
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
|
|
--spa, -s Launch in SPA mode
|
|
--universal, -u Launch in Universal mode (default)
|
|
--no-generate Don't generate static version for SPA mode (useful for nuxt start)
|
|
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
|
--quiet, -q Disable output except for errors
|
|
--help, -h Displays this message
|
|
`)
|
|
process.exit(0)
|
|
}
|
|
|
|
const options = loadNuxtConfig(argv)
|
|
|
|
// Create production build when calling `nuxt build`
|
|
options.dev = false
|
|
|
|
// Analyze option
|
|
options.build = options.build || {}
|
|
if (argv.analyze && typeof options.build.analyze !== 'object') {
|
|
options.build.analyze = true
|
|
}
|
|
|
|
// Silence output when using --quiet
|
|
if (argv.quiet) {
|
|
options.test = true
|
|
consola.level = 0
|
|
}
|
|
|
|
const nuxt = new Nuxt(options)
|
|
const builder = new Builder(nuxt)
|
|
|
|
// Setup hooks
|
|
nuxt.hook('error', err => consola.fatal(err))
|
|
|
|
// Close function
|
|
const close = () => {
|
|
// In analyze mode wait for plugin
|
|
// emitting assets and opening browser
|
|
if (options.build.analyze === true || typeof options.build.analyze === 'object') {
|
|
return
|
|
}
|
|
|
|
process.exit(0)
|
|
}
|
|
|
|
if (options.mode !== 'spa' || argv.generate === false) {
|
|
// Build only
|
|
builder
|
|
.build()
|
|
.then(close)
|
|
.catch(err => consola.fatal(err))
|
|
} else {
|
|
// Build + Generate for static deployment
|
|
new Generator(nuxt, builder)
|
|
.generate({ build: true })
|
|
.then(close)
|
|
.catch(err => consola.fatal(err))
|
|
}
|