mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
72479687d9
Co-authored-by: Aurélien Chrétien <aurelien@manager.one> Co-authored-by: Rémy Sanchez <remy.sanchez@hyperthese.net>
87 lines
2.2 KiB
JavaScript
Executable File
87 lines
2.2 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
const fs = require('fs')
|
|
const { resolve } = require('path')
|
|
const parseArgs = require('minimist')
|
|
const consola = require('consola')
|
|
const { Nuxt } = require('../dist/nuxt-start')
|
|
const { loadNuxtConfig, getLatestHost } = require('./common/utils')
|
|
|
|
const argv = parseArgs(process.argv.slice(2), {
|
|
alias: {
|
|
h: 'help',
|
|
H: 'hostname',
|
|
p: 'port',
|
|
n: 'unix-socket',
|
|
c: 'config-file',
|
|
s: 'spa',
|
|
u: 'universal'
|
|
},
|
|
boolean: ['h', 's', 'u'],
|
|
string: ['H', 'c', 'n'],
|
|
default: {
|
|
c: 'nuxt.config.js'
|
|
}
|
|
})
|
|
|
|
if (argv.hostname === '') {
|
|
consola.fatal('Provided hostname argument has no value')
|
|
}
|
|
|
|
if (argv.help) {
|
|
process.stderr.write(`
|
|
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
|
|
--unix-socket, -n Path to a UNIX socket
|
|
--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
|
|
`)
|
|
process.exit(0)
|
|
}
|
|
|
|
const options = loadNuxtConfig(argv)
|
|
|
|
// Force production mode (no webpack middleware called)
|
|
options.dev = false
|
|
|
|
const nuxt = new Nuxt(options)
|
|
|
|
// Setup hooks
|
|
nuxt.hook('error', err => consola.fatal(err))
|
|
|
|
// Check if project is built for production
|
|
const distDir = resolve(
|
|
nuxt.options.rootDir,
|
|
nuxt.options.buildDir || '.nuxt',
|
|
'dist',
|
|
'server'
|
|
)
|
|
if (!fs.existsSync(distDir)) {
|
|
consola.fatal(
|
|
'No build files found, please run `nuxt build` before launching `nuxt start`'
|
|
)
|
|
}
|
|
|
|
// Check if SSR Bundle is required
|
|
if (nuxt.options.render.ssr === true) {
|
|
const ssrBundlePath = resolve(distDir, 'server-bundle.json')
|
|
if (!fs.existsSync(ssrBundlePath)) {
|
|
consola.fatal(
|
|
'No SSR build! Please start with `nuxt start --spa` or build using `nuxt build --universal`'
|
|
)
|
|
}
|
|
}
|
|
|
|
const { port, host, socket } = getLatestHost(argv)
|
|
|
|
nuxt.listen(port, host, socket).then(() => {
|
|
nuxt.showReady(false)
|
|
})
|