From 5f17ad233f8105017683315785ce0c28d97051d5 Mon Sep 17 00:00:00 2001 From: HcySunYang Date: Tue, 5 Jan 2021 22:49:03 +0800 Subject: [PATCH 1/2] feat(runtime-dom): add a warning for isCustomElement in runtime-only build --- packages/runtime-core/src/component.ts | 2 ++ packages/runtime-core/src/index.ts | 2 +- packages/runtime-dom/src/index.ts | 23 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 788a20b4343..cba5e604962 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -654,6 +654,8 @@ type CompileFunction = ( let compile: CompileFunction | undefined +export const isRuntimeOnly = () => !compile + /** * For runtime-dom to register the compiler. * Note the exported method uses any to avoid d.ts relying on the compiler types. diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 818caa597e6..a24672226db 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -87,7 +87,7 @@ export { resolveDynamicComponent } from './helpers/resolveAssets' // For integration with runtime compiler -export { registerRuntimeCompiler } from './component' +export { registerRuntimeCompiler, isRuntimeOnly } from './component' export { useTransitionState, resolveTransitionHooks, diff --git a/packages/runtime-dom/src/index.ts b/packages/runtime-dom/src/index.ts index 0dfe9fba003..9078f49ecf7 100644 --- a/packages/runtime-dom/src/index.ts +++ b/packages/runtime-dom/src/index.ts @@ -7,7 +7,8 @@ import { Renderer, HydrationRenderer, App, - RootHydrateFunction + RootHydrateFunction, + isRuntimeOnly } from '@vue/runtime-core' import { nodeOps } from './nodeOps' import { patchProp, forcePatchProp } from './patchProp' @@ -55,6 +56,7 @@ export const createApp = ((...args) => { if (__DEV__) { injectNativeTagCheck(app) + injectCustomElementCheck(app) } const { mount } = app @@ -83,6 +85,7 @@ export const createSSRApp = ((...args) => { if (__DEV__) { injectNativeTagCheck(app) + injectCustomElementCheck(app) } const { mount } = app @@ -105,6 +108,24 @@ function injectNativeTagCheck(app: App) { }) } +function injectCustomElementCheck(app: App) { + if (isRuntimeOnly()) { + const value = app.config.isCustomElement + Object.defineProperty(app.config, 'isCustomElement', { + get() { + return value + }, + set() { + warn( + `The \`isCustomElement\` config option is only respected when using the runtime compiler.` + + `If you are using the runtime-only build, \`isCustomElement\` must be passed to \`@vue/compiler-dom\` in the build setup instead` + + `- for example, via the \`compilerOptions\` option in vue-loader: https://vue-loader.vuejs.org/options.html#compileroptions.` + ) + } + }) + } +} + function normalizeContainer( container: Element | ShadowRoot | string ): Element | null { From 952c5910dde0c60742fc432ec841e6b6bfc7fa93 Mon Sep 17 00:00:00 2001 From: HcySunYang Date: Tue, 5 Jan 2021 22:51:28 +0800 Subject: [PATCH 2/2] chore: add comments --- packages/runtime-core/src/component.ts | 1 + packages/runtime-dom/src/index.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index cba5e604962..4053e1520c1 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -654,6 +654,7 @@ type CompileFunction = ( let compile: CompileFunction | undefined +// dev only export const isRuntimeOnly = () => !compile /** diff --git a/packages/runtime-dom/src/index.ts b/packages/runtime-dom/src/index.ts index 9078f49ecf7..1edef363f88 100644 --- a/packages/runtime-dom/src/index.ts +++ b/packages/runtime-dom/src/index.ts @@ -108,6 +108,7 @@ function injectNativeTagCheck(app: App) { }) } +// dev only function injectCustomElementCheck(app: App) { if (isRuntimeOnly()) { const value = app.config.isCustomElement