From: HcySunYang Date: Wed, 24 Feb 2021 21:18:55 +0000 (+0800) Subject: dx(runtime-dom): warn config.isCustomElement usage in runtime-only build (#2945) X-Git-Tag: v3.0.7~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=354966204e1116bd805d65a643109b13bca18185;p=thirdparty%2Fvuejs%2Fcore.git dx(runtime-dom): warn config.isCustomElement usage in runtime-only build (#2945) --- diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 406e8e0e4f..9b14203621 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -653,6 +653,9 @@ type CompileFunction = ( let compile: CompileFunction | undefined +// dev only +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 818caa597e..a24672226d 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 027bef11be..8a66ec994c 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,25 @@ function injectNativeTagCheck(app: App) { }) } +// dev only +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 {