2016-11-08 00:18:26 +00:00
|
|
|
#!/usr/bin/env node
|
2018-09-28 16:23:25 +00:00
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
|
|
|
|
2017-06-16 12:42:45 +00:00
|
|
|
const fs = require('fs')
|
2017-10-31 13:16:40 +00:00
|
|
|
const { resolve } = require('path')
|
2018-03-16 19:52:17 +00:00
|
|
|
const parseArgs = require('minimist')
|
2018-03-31 16:22:14 +00:00
|
|
|
const consola = require('consola')
|
2018-08-08 16:23:47 +00:00
|
|
|
const { Nuxt } = require('../dist/nuxt-start')
|
2018-09-23 09:49:51 +00:00
|
|
|
const { loadNuxtConfig } = require('./common/utils')
|
2018-02-07 00:26:40 +00:00
|
|
|
|
2017-06-16 12:42:45 +00:00
|
|
|
const argv = parseArgs(process.argv.slice(2), {
|
2017-06-11 13:48:20 +00:00
|
|
|
alias: {
|
|
|
|
h: 'help',
|
|
|
|
H: 'hostname',
|
|
|
|
p: 'port',
|
2018-09-02 09:20:25 +00:00
|
|
|
n: 'unix-socket',
|
2017-08-18 10:54:35 +00:00
|
|
|
c: 'config-file',
|
2017-08-19 13:22:53 +00:00
|
|
|
s: 'spa',
|
|
|
|
u: 'universal'
|
2017-06-11 13:48:20 +00:00
|
|
|
},
|
2017-08-19 13:22:53 +00:00
|
|
|
boolean: ['h', 's', 'u'],
|
2018-09-02 09:20:25 +00:00
|
|
|
string: ['H', 'c', 'n'],
|
2017-06-11 13:48:20 +00:00
|
|
|
default: {
|
|
|
|
c: 'nuxt.config.js'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (argv.hostname === '') {
|
2018-04-01 20:20:46 +00:00
|
|
|
consola.fatal('Provided hostname argument has no value')
|
2017-06-11 13:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.help) {
|
2018-03-31 16:22:14 +00:00
|
|
|
process.stderr.write(`
|
2017-06-11 13:48:20 +00:00
|
|
|
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
|
2017-08-19 13:22:53 +00:00
|
|
|
--port, -p A port number on which to start the application
|
|
|
|
--hostname, -H Hostname on which to start the application
|
2018-09-02 09:20:25 +00:00
|
|
|
--unix-socket, -n Path to a UNIX socket
|
2017-08-19 13:22:53 +00:00
|
|
|
--spa Launch in SPA mode
|
|
|
|
--universal Launch in Universal mode (default)
|
|
|
|
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
|
|
|
--help, -h Displays this message
|
2017-06-11 13:48:20 +00:00
|
|
|
`)
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
|
2018-02-07 00:26:40 +00:00
|
|
|
const options = loadNuxtConfig(argv)
|
2017-06-20 11:44:47 +00:00
|
|
|
|
|
|
|
// Force production mode (no webpack middleware called)
|
|
|
|
options.dev = false
|
2016-11-09 22:59:41 +00:00
|
|
|
|
2017-08-19 10:00:40 +00:00
|
|
|
const nuxt = new Nuxt(options)
|
|
|
|
|
2018-01-11 16:11:50 +00:00
|
|
|
// Setup hooks
|
2018-07-25 15:57:43 +00:00
|
|
|
nuxt.hook('error', err => consola.fatal(err))
|
2018-01-11 16:11:50 +00:00
|
|
|
|
2017-06-16 14:04:40 +00:00
|
|
|
// Check if project is built for production
|
2018-01-11 16:11:50 +00:00
|
|
|
const distDir = resolve(
|
|
|
|
nuxt.options.rootDir,
|
|
|
|
nuxt.options.buildDir || '.nuxt',
|
2018-08-20 16:04:55 +00:00
|
|
|
'dist',
|
|
|
|
'server'
|
2018-01-11 16:11:50 +00:00
|
|
|
)
|
2017-08-05 11:45:31 +00:00
|
|
|
if (!fs.existsSync(distDir)) {
|
2018-04-01 20:20:46 +00:00
|
|
|
consola.fatal(
|
2018-01-11 16:11:50 +00:00
|
|
|
'No build files found, please run `nuxt build` before launching `nuxt start`'
|
|
|
|
)
|
2017-06-16 14:04:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 10:00:40 +00:00
|
|
|
// Check if SSR Bundle is required
|
|
|
|
if (nuxt.options.render.ssr === true) {
|
|
|
|
const ssrBundlePath = resolve(distDir, 'server-bundle.json')
|
|
|
|
if (!fs.existsSync(ssrBundlePath)) {
|
2018-04-01 20:20:46 +00:00
|
|
|
consola.fatal(
|
2018-01-11 16:11:50 +00:00
|
|
|
'No SSR build! Please start with `nuxt start --spa` or build using `nuxt build --universal`'
|
|
|
|
)
|
2017-08-19 10:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 09:49:51 +00:00
|
|
|
nuxt.listen().then(() => {
|
2018-03-31 20:20:14 +00:00
|
|
|
nuxt.showReady(false)
|
2018-03-28 22:05:27 +00:00
|
|
|
})
|