Vue Demi (French for 'half') is a foundational utility library designed for authors building universal Vue libraries that must operate seamlessly across both Vue 2 and Vue 3 environments. It intelligently abstracts away the underlying Vue version, redirecting common Composition API imports (e.g., `ref`, `reactive`, `defineComponent`) to the appropriate Vue runtime (`vue@2` with `@vue/composition-api` or `vue@3`). The current stable version is `0.14.10`, with a consistent and active release cadence that focuses on compatibility fixes, minor feature enhancements, and addressing edge cases, often seeing several patch releases per month. Its key differentiator is providing a single, unified API surface for Composition API features and core Vue utilities, enabling developers to write code once and deploy it to both major Vue versions without needing conditional imports or complex build setups. It also exposes utilities like `isVue2` and `isVue3` for version-specific logic and a `Vue2` export for safely accessing global Vue 2 APIs (e.g., `Vue.config`, `Vue.set`).
npm install vue-demiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating a universal composable function using `vue-demi`'s reactivity APIs and version detection (`isVue2`, `isVue3`), suitable for libraries supporting both Vue 2 and Vue 3.
Refer to the `vue-demi` README for the exact `peerDependencies` and `peerDependenciesMeta` configuration (e.g., `"vue": "^2.0.0 || >=3.0.0"`, `"@vue/composition-api": { "optional": true }`).Add `exclude: ['vue-demi']` to the `optimizeDeps` configuration in your `vite.config.js` or `vite.config.ts`.
Call `install()` imported from `vue-demi` at your library's entry point or plugin registration. This function is a no-op in Vue 3, making it safe to call universally.
Always check `if (Vue2)` before attempting to use any properties or methods from the `Vue2` object to avoid runtime errors in Vue 3 applications.
Ensure you are using `vue-demi` version `0.14.9` or newer, as recent updates include fixes for broader compatibility regarding `globalThis`.
Add `exclude: ['vue-demi']` to the `optimizeDeps` option in your `vite.config.js`.
Ensure `@vue/composition-api` is correctly specified as a peer dependency and consider explicitly calling `install()` from `vue-demi` in your library's entry point.
For universal code, use reactive assignments or methods like `ref()` and `reactive()`. If Vue 2-specific global API access is needed, use `if (Vue2) { Vue2.set(...) }`.Update to a browser version that supports `globalThis` (e.g., Chrome 52+, Firefox 55+, Edge 15+, Safari 10.1+). Ensure `vue-demi` is updated to at least `0.14.9` which includes compatibility fixes.