index.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {
  2. createRenderer,
  3. warn,
  4. App,
  5. RootRenderFunction
  6. } from '@vue/runtime-core'
  7. import { nodeOps } from './nodeOps'
  8. import { patchProp } from './patchProp'
  9. // Importing from the compiler, will be tree-shaken in prod
  10. import { isFunction, isString, isHTMLTag, isSVGTag } from '@vue/shared'
  11. const { render: baseRender, createApp: baseCreateApp } = createRenderer({
  12. patchProp,
  13. ...nodeOps
  14. })
  15. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  16. export const render = baseRender as RootRenderFunction<Node, Element>
  17. export const createApp = (): App<Element> => {
  18. const app = baseCreateApp()
  19. if (__DEV__) {
  20. // Inject `isNativeTag`
  21. // this is used for component name validation (dev only)
  22. Object.defineProperty(app.config, 'isNativeTag', {
  23. value: (tag: string) => isHTMLTag(tag) || isSVGTag(tag),
  24. writable: false
  25. })
  26. }
  27. const mount = app.mount
  28. app.mount = (component, container, props): any => {
  29. if (isString(container)) {
  30. container = document.querySelector(container)!
  31. if (!container) {
  32. __DEV__ &&
  33. warn(`Failed to mount app: mount target selector returned null.`)
  34. return
  35. }
  36. }
  37. if (
  38. __RUNTIME_COMPILE__ &&
  39. !isFunction(component) &&
  40. !component.render &&
  41. !component.template
  42. ) {
  43. component.template = container.innerHTML
  44. }
  45. // clear content before mounting
  46. container.innerHTML = ''
  47. return mount(component, container, props)
  48. }
  49. return app
  50. }
  51. // DOM-only runtime directive helpers
  52. export {
  53. vModelText,
  54. vModelCheckbox,
  55. vModelRadio,
  56. vModelSelect,
  57. vModelDynamic
  58. } from './directives/vModel'
  59. export { withModifiers, withKeys } from './directives/vOn'
  60. export { vShow } from './directives/vShow'
  61. // DOM-only components
  62. export { Transition, TransitionProps } from './components/Transition'
  63. export {
  64. TransitionGroup,
  65. TransitionGroupProps
  66. } from './components/TransitionGroup'
  67. // re-export everything from core
  68. // h, Component, reactivity API, nextTick, flags & types
  69. export * from '@vue/runtime-core'