mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 06:35:10 +00:00
264c543aaf
* feat(builder): add --no-generate option for SPA mode with v1.x version * update upath to 1.1.0 * update to puppeteer@1.9.0
105 lines
2.6 KiB
JavaScript
Executable File
105 lines
2.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/* eslint-disable no-console */
|
|
|
|
const parseArgs = require('minimist')
|
|
const debug = require('debug')('nuxt:build')
|
|
debug.color = 2 // Force green color
|
|
|
|
const { Nuxt, Builder, Generator, Utils } = 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) {
|
|
console.log(`
|
|
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
|
|
}
|
|
|
|
debug('Building...')
|
|
const nuxt = new Nuxt(options)
|
|
const builder = new Builder(nuxt)
|
|
|
|
// Setup hooks
|
|
nuxt.hook('error', (_err, from) => Utils.fatalError(_err, from))
|
|
|
|
// Close function
|
|
const close = () => {
|
|
if (options.build.analyze === true) {
|
|
return // Wait for user exit
|
|
}
|
|
process.exit(0)
|
|
}
|
|
|
|
if (options.mode !== 'spa' || argv.generate === false) {
|
|
// -- Build Only --
|
|
builder
|
|
.build()
|
|
.then(() => debug('Building done'))
|
|
.then(() => close())
|
|
.catch(Utils.fatalError)
|
|
} else {
|
|
// -- Build for SPA app --
|
|
const s = Date.now()
|
|
|
|
nuxt.hook('generate:distRemoved', () => debug('Destination folder cleaned'))
|
|
|
|
nuxt.hook('generate:distCopied', () => debug('Static & build files copied'))
|
|
|
|
nuxt.hook('generate:page', page => debug('Generate file: ' + page.path))
|
|
|
|
nuxt.hook('generate:done', (generator, errors) => {
|
|
const duration = Math.round((Date.now() - s) / 100) / 10
|
|
|
|
debug(`HTML Files generated in ${duration}s`)
|
|
|
|
if (errors.length) {
|
|
/* eslint-disable no-console */
|
|
console.log('\n' + errors.toString())
|
|
}
|
|
})
|
|
|
|
// Disable minify to get exact results of nuxt start
|
|
nuxt.options.generate.minify = false
|
|
|
|
// Generate dist for SPA static deployment
|
|
new Generator(nuxt, builder).generate({ build: true }).then(() => {
|
|
close()
|
|
})
|
|
}
|