Nuxt/bin/nuxt-start

64 lines
1.7 KiB
Plaintext
Raw Normal View History

2016-11-08 00:18:26 +00:00
#!/usr/bin/env node
2016-11-07 01:34:58 +00:00
2016-12-09 18:40:59 +00:00
var fs = require('fs')
2017-06-11 13:48:20 +00:00
var parseArgs = require('minimist')
2016-12-09 18:40:59 +00:00
var Nuxt = require('../')
var resolve = require('path').resolve
2016-11-07 01:34:58 +00:00
2017-06-11 13:48:20 +00:00
var argv = parseArgs(process.argv.slice(2), {
alias: {
h: 'help',
H: 'hostname',
p: 'port',
c: 'config-file'
},
boolean: ['h'],
string: ['H', 'c'],
default: {
c: 'nuxt.config.js'
}
})
if (argv.hostname === '') {
console.error(`> Provided hostname argument has no value`)
process.exit(1)
}
if (argv.help) {
console.log(`
Description
Starts the application in production mode.
The application should be compiled with \`nuxt build\` first.
Usage
$ nuxt start <dir> -p <port number> -H <hostname>
Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application
--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'])
2016-12-07 17:47:47 +00:00
2016-12-09 18:40:59 +00:00
var options = {}
2016-11-07 01:34:58 +00:00
if (fs.existsSync(nuxtConfigFile)) {
options = require(nuxtConfigFile)
2017-06-11 13:48:20 +00:00
} else if (argv['config-file'] !== 'nuxt.config.js') {
console.error(`> Could not load config file ${argv['config-file']}`)
process.exit(1)
2016-11-07 01:34:58 +00:00
}
if (typeof options.rootDir !== 'string') {
options.rootDir = rootDir
}
2017-02-03 14:09:27 +00:00
options.dev = false // Force production mode (no webpack middleware called)
var nuxt = new Nuxt(options)
2017-06-11 13:48:20 +00:00
var port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port
var host = argv.hostname || process.env.HOST || process.env.npm_package_config_nuxt_host
new Nuxt.Server(nuxt).listen(port, host)
module.exports = nuxt