mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
63fe3fd803
useful for SPA builds that don't need static dist/ to be generated
80 lines
1.9 KiB
JavaScript
Executable File
80 lines
1.9 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'
|
|
},
|
|
boolean: ['h', 'a', 's', 'u'],
|
|
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 Launch in SPA mode
|
|
--universal 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)
|
|
--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) {
|
|
options.build.analyze = true
|
|
}
|
|
|
|
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) {
|
|
return
|
|
}
|
|
|
|
process.exit(0)
|
|
}
|
|
|
|
if (options.mode !== 'spa' || argv.generate === false) {
|
|
// Build only
|
|
builder
|
|
.build()
|
|
.then(() => close())
|
|
.catch(error => consola.fatal(error))
|
|
} else {
|
|
// Build + Generate for static deployment
|
|
new Generator(nuxt, builder)
|
|
.generate({ build: true })
|
|
.then(() => close())
|
|
.catch(error => consola.fatal(error))
|
|
}
|