From e3974b4729bfe1784f75337bab61a63bc2a5d0c9 Mon Sep 17 00:00:00 2001 From: Sebastien Chopin Date: Fri, 20 Oct 2017 12:05:22 +0200 Subject: [PATCH] deprecation: Deprecate isServer, isClient and dev --- lib/app/index.js | 2 -- lib/app/server.js | 2 +- lib/app/utils.js | 14 ++++++++++---- lib/builder/webpack/client.config.js | 8 +++++++- lib/builder/webpack/server.config.js | 8 +++++++- lib/core/renderer.js | 2 -- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/app/index.js b/lib/app/index.js index ffbe374972..b40dec9436 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -107,8 +107,6 @@ async function createApp (ssrContext) { // Set context to app.context await setContext(app, { - isServer: !!ssrContext, - isClient: !ssrContext, route, next, error: app.nuxt.error.bind(app), diff --git a/lib/app/server.js b/lib/app/server.js index 427633defc..61175aac5e 100644 --- a/lib/app/server.js +++ b/lib/app/server.js @@ -207,6 +207,6 @@ export default async ssrContext => { // Call beforeNuxtRender methods & add store state await beforeRender() - + return _app } diff --git a/lib/app/utils.js b/lib/app/utils.js index bffc4fba74..f3cbeefc7f 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -102,8 +102,14 @@ export async function setContext(app, context) { // If context not defined, create it if (!app.context) { app.context = { - isServer: !!context.isServer, - isClient: !!context.isClient, + get isServer() { + 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, isDev: <%= isDev %>, isHMR: false, @@ -132,8 +138,8 @@ export async function setContext(app, context) { status: status }) } - if (app.context.isServer) app.context.beforeNuxtRender = (fn) => context.beforeRenderFns.push(fn) - if (app.context.isClient) app.context.nuxtState = window.__NUXT__ + if (process.server) app.context.beforeNuxtRender = (fn) => context.beforeRenderFns.push(fn) + if (process.client) app.context.nuxtState = window.__NUXT__ } // Dynamic keys app.context.next = context.next diff --git a/lib/builder/webpack/client.config.js b/lib/builder/webpack/client.config.js index 7f6a5da9ea..eee26861ef 100644 --- a/lib/builder/webpack/client.config.js +++ b/lib/builder/webpack/client.config.js @@ -129,6 +129,7 @@ export default function webpackClientConfig () { 'process.env.VUE_ENV': JSON.stringify('client'), 'process.mode': JSON.stringify(this.options.mode), 'process.browser': true, + 'process.client': true, 'process.server': false, 'process.static': this.isStatic })) @@ -220,8 +221,13 @@ export default function webpackClientConfig () { // Extend config if (typeof this.options.build.extend === 'function') { + const isDev = this.options.dev 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 }) // Only overwrite config when something is returned for backwards compatibility diff --git a/lib/builder/webpack/server.config.js b/lib/builder/webpack/server.config.js index 7009ed5603..6e2ebf6cfc 100644 --- a/lib/builder/webpack/server.config.js +++ b/lib/builder/webpack/server.config.js @@ -43,6 +43,7 @@ export default function webpackServerConfig () { 'process.env.VUE_ENV': JSON.stringify('server'), 'process.mode': JSON.stringify(this.options.mode), 'process.browser': false, + 'process.client': false, 'process.server': true, 'process.static': this.isStatic })) @@ -75,8 +76,13 @@ export default function webpackServerConfig () { // Extend config if (typeof this.options.build.extend === 'function') { + const isDev = this.options.dev 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 }) // Only overwrite config when something is returned for backwards compatibility diff --git a/lib/core/renderer.js b/lib/core/renderer.js index 0bdef1ab06..97ce462f90 100644 --- a/lib/core/renderer.js +++ b/lib/core/renderer.js @@ -111,7 +111,6 @@ export default class Renderer extends Tapable { await this.applyPluginsAsync('resourcesLoaded', this.resources) if (updated.length > 0) { - // debug('Updated', updated.join(', '), isServer) this.createRenderer() } } @@ -484,7 +483,6 @@ export default class Renderer extends Tapable { // Add url and isSever to the context context.url = url - context.isServer = true // Basic response if SSR is disabled or spa data provided const spa = context.spa || (context.res && context.res.spa)