createCompatVue.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // This entry exports the runtime only, and is built as
  2. // `dist/vue.esm-bundler.js` which is used by default for bundlers.
  3. import { initDev } from './dev'
  4. import {
  5. type CompatVue,
  6. DeprecationTypes,
  7. KeepAlive,
  8. Transition,
  9. TransitionGroup,
  10. compatUtils,
  11. createApp,
  12. vModelDynamic,
  13. vShow,
  14. } from '@vue/runtime-dom'
  15. import { extend } from '@vue/shared'
  16. if (__DEV__) {
  17. initDev()
  18. }
  19. import * as runtimeDom from '@vue/runtime-dom'
  20. function wrappedCreateApp(...args: any[]) {
  21. // @ts-expect-error
  22. const app = createApp(...args)
  23. if (compatUtils.isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, null)) {
  24. // register built-in components so that they can be resolved via strings
  25. // in the legacy h() call. The __compat__ prefix is to ensure that v3 h()
  26. // doesn't get affected.
  27. app.component('__compat__transition', Transition)
  28. app.component('__compat__transition-group', TransitionGroup)
  29. app.component('__compat__keep-alive', KeepAlive)
  30. // built-in directives. No need for prefix since there's no render fn API
  31. // for resolving directives via string in v3.
  32. app._context.directives.show = vShow
  33. app._context.directives.model = vModelDynamic
  34. }
  35. return app
  36. }
  37. export function createCompatVue(): CompatVue {
  38. const Vue = compatUtils.createCompatVue(createApp, wrappedCreateApp)
  39. extend(Vue, runtimeDom)
  40. return Vue
  41. }