From 06884c89c39387341cc6998719f92470d2096b3c Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 17 Jun 2020 17:53:39 -0400 Subject: [PATCH] refactor: tweak devtools --- packages/runtime-dom/src/devtools.ts | 6 ------ packages/runtime-dom/src/index.ts | 1 - packages/vue/src/dev.ts | 16 ++++++++++++++++ packages/vue/src/devCheck.ts | 7 ------- packages/vue/src/index.ts | 4 +++- packages/vue/src/runtime.ts | 4 +++- 6 files changed, 22 insertions(+), 16 deletions(-) delete mode 100644 packages/runtime-dom/src/devtools.ts create mode 100644 packages/vue/src/dev.ts delete mode 100644 packages/vue/src/devCheck.ts diff --git a/packages/runtime-dom/src/devtools.ts b/packages/runtime-dom/src/devtools.ts deleted file mode 100644 index b2191700d60..00000000000 --- a/packages/runtime-dom/src/devtools.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { setDevtoolsHook } from '@vue/runtime-core' - -const target: any = __BROWSER__ ? window : global - -target.__VUE__ = true -setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__) diff --git a/packages/runtime-dom/src/index.ts b/packages/runtime-dom/src/index.ts index 1bf1e59171d..0dbdd846ecb 100644 --- a/packages/runtime-dom/src/index.ts +++ b/packages/runtime-dom/src/index.ts @@ -13,7 +13,6 @@ import { nodeOps } from './nodeOps' import { patchProp } from './patchProp' // Importing from the compiler, will be tree-shaken in prod import { isFunction, isString, isHTMLTag, isSVGTag, extend } from '@vue/shared' -import './devtools' declare module '@vue/reactivity' { export interface RefUnwrapBailTypes { diff --git a/packages/vue/src/dev.ts b/packages/vue/src/dev.ts new file mode 100644 index 00000000000..f24c01878da --- /dev/null +++ b/packages/vue/src/dev.ts @@ -0,0 +1,16 @@ +import { version, setDevtoolsHook } from '@vue/runtime-dom' + +export function initDev() { + const target: any = __BROWSER__ ? window : global + + target.__VUE__ = version + setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__) + + if (__BROWSER__) { + // @ts-ignore `console.info` cannot be null error + console[console.info ? 'info' : 'log']( + `You are running a development build of Vue.\n` + + `Make sure to use the production build (*.prod.js) when deploying for production.` + ) + } +} diff --git a/packages/vue/src/devCheck.ts b/packages/vue/src/devCheck.ts deleted file mode 100644 index 07aaab4a58d..00000000000 --- a/packages/vue/src/devCheck.ts +++ /dev/null @@ -1,7 +0,0 @@ -if (__BROWSER__ && __DEV__) { - // @ts-ignore `console.info` cannot be null error - console[console.info ? 'info' : 'log']( - `You are running a development build of Vue.\n` + - `Make sure to use the production build (*.prod.js) when deploying for production.` - ) -} diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts index d6a472a2046..a9ccf894ef9 100644 --- a/packages/vue/src/index.ts +++ b/packages/vue/src/index.ts @@ -1,11 +1,13 @@ // This entry is the "full-build" that includes both the runtime // and the compiler, and supports on-the-fly compilation of the template option. -import './devCheck' +import { initDev } from './dev' import { compile, CompilerOptions, CompilerError } from '@vue/compiler-dom' import { registerRuntimeCompiler, RenderFunction, warn } from '@vue/runtime-dom' import * as runtimeDom from '@vue/runtime-dom' import { isString, NOOP, generateCodeFrame, extend } from '@vue/shared' +__DEV__ && initDev() + const compileCache: Record = Object.create(null) function compileToFunction( diff --git a/packages/vue/src/runtime.ts b/packages/vue/src/runtime.ts index fdbdd153d27..b78d60c9935 100644 --- a/packages/vue/src/runtime.ts +++ b/packages/vue/src/runtime.ts @@ -1,8 +1,10 @@ // This entry exports the runtime only, and is built as // `dist/vue.esm-bundler.js` which is used by default for bundlers. -import './devCheck' +import { initDev } from './dev' import { warn } from '@vue/runtime-dom' +__DEV__ && initDev() + export * from '@vue/runtime-dom' export const compile = () => {