#!/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 Options --analyze, -a Launch webpack-bundle-analyzer to optimize your bundles. --spa Launch in SPA mode --universal Launch in Universal mode (default) --generate Generate static version after build --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 (!argv.generate) { // -- Build only -- builder .build() .then(() => close()) .catch(error => consola.fatal(error)) } else { // Generate dist for SPA static deployment new Generator(nuxt, builder).generate({ build: true }).then(() => { close() }) }