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