chore(config): deprecate mode option (#8044)

This commit is contained in:
pooya parsa 2020-09-09 14:39:20 +00:00 committed by GitHub
parent c9513010eb
commit d864b2bd75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 7 deletions

View File

@ -1,6 +1,6 @@
import capitalize from 'lodash/capitalize'
import env from 'std-env'
import { TARGETS, MODES } from '@nuxt/utils'
import { TARGETS } from '@nuxt/utils'
export default () => ({
// Env
@ -17,9 +17,10 @@ export default () => ({
// Rendering
ssr: true,
// TODO: remove in Nuxt 3
// Mode
mode: MODES.universal,
// Mode (deprecated)
mode: undefined,
// Modern
modern: undefined,
// Modules

View File

@ -97,6 +97,18 @@ export function getNuxtConfig (_options) {
options.target = 'server'
}
// Deprecate Mode
if (options.mode) {
if ((options.mode === MODES.universal && options.ssr) || (options.mode === MODES.spa && !options.ssr)) {
consola.warn('`mode` option is deprecated. You can safely remove it from `nuxt.config`')
} else {
consola.warn('`mode` option is deprecated. Please use `ssr: true` for universal mode or `ssr: false` for spa mode and remove `mode` from `nuxt.config`')
}
} else {
// For backward compat we need default value
options.mode = MODES.universal
}
// SSR root option
if (options.ssr === false) {
options.mode = MODES.spa

View File

@ -241,7 +241,7 @@ Object {
"server_error": "Server error",
"server_error_details": "An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.",
},
"mode": "universal",
"mode": undefined,
"modern": undefined,
"modes": Object {
"spa": Object {
@ -617,7 +617,7 @@ Object {
"server_error": "Server error",
"server_error_details": "An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.",
},
"mode": "universal",
"mode": undefined,
"modern": undefined,
"modes": Object {
"spa": Object {

View File

@ -50,6 +50,7 @@ export interface NuxtOptions extends Configuration {
layoutTransition: Transition
loading: NuxtOptionsLoading | false | string
loadingIndicator: NuxtOptionsLoadingIndicator | false | string
/** @deprecated Use ssr option instead */
mode: 'spa' | 'universal'
target: 'server' | 'static'
modern: 'client' | 'server' | boolean

View File

@ -14,10 +14,11 @@ const hooks = [
describe('with-config', () => {
buildFixture('with-config', () => {
expect(consola.warn).toHaveBeenCalledTimes(7)
expect(consola.warn).toHaveBeenCalledTimes(8)
expect(consola.fatal).toHaveBeenCalledTimes(0)
expect(consola.warn.mock.calls).toMatchObject([
['`router.scrollBehavior` property is deprecated in favor of using `~/app/router.scrollBehavior.js` file, learn more: https://nuxtjs.org/api/configuration-router#scrollbehavior'],
['`mode` option is deprecated. Please use `ssr: true` for universal mode or `ssr: false` for spa mode and remove `mode` from `nuxt.config`'],
['Unknown mode: unknown. Falling back to universal'],
['Invalid plugin mode (server/client/all): \'abc\'. Falling back to \'all\''],
[{