mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
simplify modes
This commit is contained in:
parent
278180b4fe
commit
a289a55a72
@ -15,10 +15,11 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
h: 'help',
|
||||
c: 'config-file',
|
||||
a: 'analyze',
|
||||
m: 'mode'
|
||||
s: 'spa',
|
||||
u: 'universal'
|
||||
},
|
||||
boolean: ['h', 'a'],
|
||||
string: ['c', 'm'],
|
||||
boolean: ['h', 'a', 's', 'u'],
|
||||
string: ['c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -31,10 +32,11 @@ if (argv.help) {
|
||||
Usage
|
||||
$ nuxt build <dir>
|
||||
Options
|
||||
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
|
||||
--mode, -m [spa|universal|ssr-only] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--analyze, -a Launch webpack-bundle-analyzer to optimize your bundles.
|
||||
--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)
|
||||
}
|
||||
@ -56,9 +58,7 @@ if (typeof options.rootDir !== 'string') {
|
||||
options.dev = false
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
options.mode = (argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
// Analyze option
|
||||
options.build = options.build || {}
|
||||
@ -89,4 +89,3 @@ if (options.mode !== 'spa') {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
22
bin/nuxt-dev
22
bin/nuxt-dev
@ -18,10 +18,11 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
H: 'hostname',
|
||||
p: 'port',
|
||||
c: 'config-file',
|
||||
m: 'mode'
|
||||
s: 'spa',
|
||||
u: 'universal'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['H', 'c', 'm'],
|
||||
boolean: ['h', 's', 'u'],
|
||||
string: ['H', 'c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -40,11 +41,12 @@ if (argv.help) {
|
||||
Usage
|
||||
$ nuxt dev <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
|
||||
--mode, -m [spa|universal|ssr-only] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--port, -p A port number on which to start the application
|
||||
--hostname, -H Hostname on which to start the application
|
||||
--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)
|
||||
}
|
||||
@ -112,9 +114,7 @@ function loadNuxtConfig () {
|
||||
options.dev = true
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
options.mode = (argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
return options
|
||||
}
|
||||
|
@ -14,10 +14,11 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
alias: {
|
||||
h: 'help',
|
||||
c: 'config-file',
|
||||
m: 'mode'
|
||||
s: 'spa',
|
||||
u: 'universal'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['c', 'm'],
|
||||
boolean: ['h', 's', 'u'],
|
||||
string: ['c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -30,9 +31,11 @@ if (argv.help) {
|
||||
Usage
|
||||
$ nuxt generate <dir>
|
||||
Options
|
||||
--mode, -m [spa|universal|ssr-only] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--spa Launch in SPA mode
|
||||
--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)
|
||||
}
|
||||
@ -53,9 +56,7 @@ if (typeof options.rootDir !== 'string') {
|
||||
options.dev = false // Force production mode (no webpack middleware called)
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
options.mode = (argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
debug('Generating...')
|
||||
const nuxt = new Nuxt(options)
|
||||
|
@ -11,10 +11,11 @@ const argv = parseArgs(process.argv.slice(2), {
|
||||
H: 'hostname',
|
||||
p: 'port',
|
||||
c: 'config-file',
|
||||
m: 'mode'
|
||||
s: 'spa',
|
||||
u: 'universal'
|
||||
},
|
||||
boolean: ['h'],
|
||||
string: ['H', 'c', 'm'],
|
||||
boolean: ['h', 's', 'u'],
|
||||
string: ['H', 'c'],
|
||||
default: {
|
||||
c: 'nuxt.config.js'
|
||||
}
|
||||
@ -33,11 +34,12 @@ if (argv.help) {
|
||||
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
|
||||
--mode, -m [spa|universal|ssr-only] Nuxt Mode (default: universal)
|
||||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js)
|
||||
--help, -h Displays this message
|
||||
--port, -p A port number on which to start the application
|
||||
--hostname, -H Hostname on which to start the application
|
||||
--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)
|
||||
}
|
||||
@ -62,9 +64,7 @@ if (typeof options.rootDir !== 'string') {
|
||||
options.dev = false
|
||||
|
||||
// Nuxt Mode
|
||||
if (argv['mode']) {
|
||||
options.mode = argv['mode']
|
||||
}
|
||||
options.mode = (argv['spa'] && 'spa') || (argv['universal'] && 'universal') || options.mode
|
||||
|
||||
const nuxt = new Nuxt(options)
|
||||
|
||||
@ -80,7 +80,7 @@ if (nuxt.options.render.ssr === true) {
|
||||
const ssrBundlePath = resolve(distDir, 'server-bundle.json')
|
||||
if (!fs.existsSync(ssrBundlePath)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('> No SSR build! Please start with `-m spa` flag or build using `nuxt build -m universal`')
|
||||
console.error('> No SSR build! Please start with `nuxt start --spa` or build using `nuxt build --universal`')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -126,17 +126,9 @@ Options.from = function (_options) {
|
||||
options.cssSourceMap = options.dev
|
||||
}
|
||||
|
||||
// Resolve mode
|
||||
let mode = options.mode
|
||||
if (typeof mode === 'function') {
|
||||
mode = mode()
|
||||
}
|
||||
if (typeof mode === 'string') {
|
||||
mode = Options.modes[mode]
|
||||
}
|
||||
|
||||
// Apply mode
|
||||
_.defaultsDeep(options, mode)
|
||||
// Apply mode preset
|
||||
let modePreset = Options.modes[options.mode || 'universal'] || Options.modes['universal']
|
||||
_.defaultsDeep(options, modePreset)
|
||||
|
||||
// If no server-side rendering, add appear true transition
|
||||
if (options.render.ssr === false) {
|
||||
@ -162,14 +154,6 @@ Options.modes = {
|
||||
render: {
|
||||
ssr: false
|
||||
}
|
||||
},
|
||||
static: {
|
||||
build: {
|
||||
ssr: true
|
||||
},
|
||||
render: {
|
||||
ssr: 'only'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user