diff --git a/bin/nuxt-build b/bin/nuxt-build index 12a52eb1fa..1d3a290e89 100755 --- a/bin/nuxt-build +++ b/bin/nuxt-build @@ -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 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') { } }) } - diff --git a/bin/nuxt-dev b/bin/nuxt-dev index 5d680140dc..488d3970c2 100755 --- a/bin/nuxt-dev +++ b/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 -p -H 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 } diff --git a/bin/nuxt-generate b/bin/nuxt-generate index 5f549abd0c..f86cd43eba 100755 --- a/bin/nuxt-generate +++ b/bin/nuxt-generate @@ -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 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) diff --git a/bin/nuxt-start b/bin/nuxt-start index b8c26b9321..632bba2726 100755 --- a/bin/nuxt-start +++ b/bin/nuxt-start @@ -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 -p -H 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) } } diff --git a/lib/common/options.js b/lib/common/options.js index 28ad3a3e2a..c25e68371f 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -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' - } } }