Nuxt/bin/nuxt-build

72 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env node
2016-11-10 14:24:22 +00:00
// Show logs
process.env.DEBUG = 'nuxt:*'
2016-12-09 18:40:59 +00:00
var fs = require('fs')
2017-06-11 13:48:20 +00:00
var parseArgs = require('minimist')
2017-01-23 16:55:39 +00:00
var without = require('lodash').without
2016-12-09 18:40:59 +00:00
var Nuxt = require('../')
var resolve = require('path').resolve
2017-06-11 13:48:20 +00:00
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'
}
})
2017-06-11 13:48:20 +00:00
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)
}
2017-06-11 13:48:20 +00:00
var rootDir = resolve(argv._[0] || '.')
var nuxtConfigFile = resolve(rootDir, argv['config-file'])
2016-12-07 18:01:46 +00:00
2016-12-09 18:40:59 +00:00
var options = {}
2017-06-11 13:48:20 +00:00
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
}
2017-06-11 13:48:20 +00:00
// Create production build when calling `nuxt build`
options.dev = false
2017-06-14 18:51:14 +00:00
options.runBuild = true // Force doing production build before init
2017-06-11 13:48:20 +00:00
// Analyze option
2017-01-23 16:55:39 +00:00
options.build = options.build || {}
2017-06-11 13:48:20 +00:00
if (argv.analyze) {
options.build.analyze = true
2017-01-24 19:25:56 +00:00
}
2017-01-23 16:55:39 +00:00
2016-12-08 15:41:20 +00:00
console.log('[nuxt] Building...') // eslint-disable-line no-console
var nuxt = module.exports = new Nuxt(options)
2017-06-15 14:59:26 +00:00
nuxt.ready()
2017-06-11 13:48:20 +00:00
.then(() => {
console.log('[nuxt] Building done') // eslint-disable-line no-console
})
.catch((err) => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})