mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
deprecation: Deprecate isServer, isClient and dev
This commit is contained in:
parent
d1ed762c1b
commit
e3974b4729
@ -107,8 +107,6 @@ async function createApp (ssrContext) {
|
|||||||
|
|
||||||
// Set context to app.context
|
// Set context to app.context
|
||||||
await setContext(app, {
|
await setContext(app, {
|
||||||
isServer: !!ssrContext,
|
|
||||||
isClient: !ssrContext,
|
|
||||||
route,
|
route,
|
||||||
next,
|
next,
|
||||||
error: app.nuxt.error.bind(app),
|
error: app.nuxt.error.bind(app),
|
||||||
|
@ -102,8 +102,14 @@ export async function setContext(app, context) {
|
|||||||
// If context not defined, create it
|
// If context not defined, create it
|
||||||
if (!app.context) {
|
if (!app.context) {
|
||||||
app.context = {
|
app.context = {
|
||||||
isServer: !!context.isServer,
|
get isServer() {
|
||||||
isClient: !!context.isClient,
|
console.warn('context.isServer has been deprecated, please use process.server instead.')
|
||||||
|
return process.server
|
||||||
|
},
|
||||||
|
get isClient() {
|
||||||
|
console.warn('context.isClient has been deprecated, please use process.client instead.')
|
||||||
|
return process.client
|
||||||
|
},
|
||||||
isStatic: process.static,
|
isStatic: process.static,
|
||||||
isDev: <%= isDev %>,
|
isDev: <%= isDev %>,
|
||||||
isHMR: false,
|
isHMR: false,
|
||||||
@ -132,8 +138,8 @@ export async function setContext(app, context) {
|
|||||||
status: status
|
status: status
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (app.context.isServer) app.context.beforeNuxtRender = (fn) => context.beforeRenderFns.push(fn)
|
if (process.server) app.context.beforeNuxtRender = (fn) => context.beforeRenderFns.push(fn)
|
||||||
if (app.context.isClient) app.context.nuxtState = window.__NUXT__
|
if (process.client) app.context.nuxtState = window.__NUXT__
|
||||||
}
|
}
|
||||||
// Dynamic keys
|
// Dynamic keys
|
||||||
app.context.next = context.next
|
app.context.next = context.next
|
||||||
|
@ -129,6 +129,7 @@ export default function webpackClientConfig () {
|
|||||||
'process.env.VUE_ENV': JSON.stringify('client'),
|
'process.env.VUE_ENV': JSON.stringify('client'),
|
||||||
'process.mode': JSON.stringify(this.options.mode),
|
'process.mode': JSON.stringify(this.options.mode),
|
||||||
'process.browser': true,
|
'process.browser': true,
|
||||||
|
'process.client': true,
|
||||||
'process.server': false,
|
'process.server': false,
|
||||||
'process.static': this.isStatic
|
'process.static': this.isStatic
|
||||||
}))
|
}))
|
||||||
@ -220,8 +221,13 @@ export default function webpackClientConfig () {
|
|||||||
|
|
||||||
// Extend config
|
// Extend config
|
||||||
if (typeof this.options.build.extend === 'function') {
|
if (typeof this.options.build.extend === 'function') {
|
||||||
|
const isDev = this.options.dev
|
||||||
const extendedConfig = this.options.build.extend.call(this, config, {
|
const extendedConfig = this.options.build.extend.call(this, config, {
|
||||||
dev: this.options.dev,
|
get dev () {
|
||||||
|
console.warn('dev has been deprecated into build.extend, please use isDev') // eslint-disable-line no-console
|
||||||
|
return isDev
|
||||||
|
},
|
||||||
|
isDev,
|
||||||
isClient: true
|
isClient: true
|
||||||
})
|
})
|
||||||
// Only overwrite config when something is returned for backwards compatibility
|
// Only overwrite config when something is returned for backwards compatibility
|
||||||
|
@ -43,6 +43,7 @@ export default function webpackServerConfig () {
|
|||||||
'process.env.VUE_ENV': JSON.stringify('server'),
|
'process.env.VUE_ENV': JSON.stringify('server'),
|
||||||
'process.mode': JSON.stringify(this.options.mode),
|
'process.mode': JSON.stringify(this.options.mode),
|
||||||
'process.browser': false,
|
'process.browser': false,
|
||||||
|
'process.client': false,
|
||||||
'process.server': true,
|
'process.server': true,
|
||||||
'process.static': this.isStatic
|
'process.static': this.isStatic
|
||||||
}))
|
}))
|
||||||
@ -75,8 +76,13 @@ export default function webpackServerConfig () {
|
|||||||
|
|
||||||
// Extend config
|
// Extend config
|
||||||
if (typeof this.options.build.extend === 'function') {
|
if (typeof this.options.build.extend === 'function') {
|
||||||
|
const isDev = this.options.dev
|
||||||
const extendedConfig = this.options.build.extend.call(this, config, {
|
const extendedConfig = this.options.build.extend.call(this, config, {
|
||||||
dev: this.options.dev,
|
get dev () {
|
||||||
|
console.warn('dev has been deprecated into build.extend, please use isDev') // eslint-disable-line no-console
|
||||||
|
return isDev
|
||||||
|
},
|
||||||
|
isDev,
|
||||||
isServer: true
|
isServer: true
|
||||||
})
|
})
|
||||||
// Only overwrite config when something is returned for backwards compatibility
|
// Only overwrite config when something is returned for backwards compatibility
|
||||||
|
@ -111,7 +111,6 @@ export default class Renderer extends Tapable {
|
|||||||
await this.applyPluginsAsync('resourcesLoaded', this.resources)
|
await this.applyPluginsAsync('resourcesLoaded', this.resources)
|
||||||
|
|
||||||
if (updated.length > 0) {
|
if (updated.length > 0) {
|
||||||
// debug('Updated', updated.join(', '), isServer)
|
|
||||||
this.createRenderer()
|
this.createRenderer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,7 +483,6 @@ export default class Renderer extends Tapable {
|
|||||||
|
|
||||||
// Add url and isSever to the context
|
// Add url and isSever to the context
|
||||||
context.url = url
|
context.url = url
|
||||||
context.isServer = true
|
|
||||||
|
|
||||||
// Basic response if SSR is disabled or spa data provided
|
// Basic response if SSR is disabled or spa data provided
|
||||||
const spa = context.spa || (context.res && context.res.spa)
|
const spa = context.spa || (context.res && context.res.spa)
|
||||||
|
Loading…
Reference in New Issue
Block a user