mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-18 02:07:14 +00:00
70 lines
1.7 KiB
JavaScript
Executable File
70 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
// Show logs
|
|
process.env.DEBUG = 'nuxt:*'
|
|
|
|
var fs = require('fs')
|
|
var parseArgs = require('minimist')
|
|
var without = require('lodash').without
|
|
var Nuxt = require('../')
|
|
var resolve = require('path').resolve
|
|
|
|
const argv = parseArgs(process.argv.slice(2), {
|
|
alias: {
|
|
h: 'help',
|
|
c: 'config-file',
|
|
a: 'analyze'
|
|
},
|
|
boolean: ['h', 'a'],
|
|
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.
|
|
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
|
--help, -h Displays this message
|
|
`)
|
|
process.exit(0)
|
|
}
|
|
|
|
var rootDir = resolve(argv._[0] || '.')
|
|
var nuxtConfigFile = resolve(rootDir, argv['config-file'])
|
|
|
|
var options = {}
|
|
if (fs.existsSync(nuxtConfigFile)) {
|
|
options = require(nuxtConfigFile)
|
|
} else if (argv['config-file'] !== 'nuxt.config.js') {
|
|
console.error(`> Could not load config file ${argv['config-file']}`)
|
|
process.exit(1)
|
|
}
|
|
if (typeof options.rootDir !== 'string') {
|
|
options.rootDir = rootDir
|
|
}
|
|
// Create production build when calling `nuxt build`
|
|
options.dev = false
|
|
// Analyze option
|
|
options.build = options.build || {}
|
|
if (argv.analyze) {
|
|
options.build.analyze = true
|
|
}
|
|
|
|
console.log('[nuxt] Building...') // eslint-disable-line no-console
|
|
var nuxt = module.exports = 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)
|
|
})
|