Skip to content

Commit

Permalink
dx(runtime-dom): warn config.isCustomElement usage in runtime-only bu…
Browse files Browse the repository at this point in the history
…ild (#2945)
  • Loading branch information
HcySunYang authored Feb 24, 2021
1 parent d0ea745 commit 3549662
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 23 additions & 1 deletion packages/runtime-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Renderer,
HydrationRenderer,
App,
RootHydrateFunction
RootHydrateFunction,
isRuntimeOnly
} from '@vue/runtime-core'
import { nodeOps } from './nodeOps'
import { patchProp, forcePatchProp } from './patchProp'
Expand Down Expand Up @@ -55,6 +56,7 @@ export const createApp = ((...args) => {

if (__DEV__) {
injectNativeTagCheck(app)
injectCustomElementCheck(app)
}

const { mount } = app
Expand Down Expand Up @@ -83,6 +85,7 @@ export const createSSRApp = ((...args) => {

if (__DEV__) {
injectNativeTagCheck(app)
injectCustomElementCheck(app)
}

const { mount } = app
Expand All @@ -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 {
Expand Down

0 comments on commit 3549662

Please sign in to comment.