Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
The vue-demi package is a utility that enables library authors to publish their libraries for both Vue 2 and Vue 3 with a single codebase. It provides a set of APIs that are compatible with both versions of Vue, allowing for seamless integration and use in projects that may be using either version.
Unified Vue Hooks
vue-demi provides a way to detect the version of Vue being used and allows you to conditionally execute code based on the version. This is useful for handling differences in the Vue lifecycle hooks or other version-specific features.
import { isVue2, isVue3, Vue2, Vue3 } from 'vue-demi'
if (isVue2) {
// Vue 2 specific logic
} else if (isVue3) {
// Vue 3 specific logic
}
Reactive API
vue-demi exports the reactive composition API that is consistent across Vue 2 and Vue 3. This allows developers to use the reactive system without worrying about the underlying Vue version.
import { ref, reactive } from 'vue-demi'
const count = ref(0)
const state = reactive({ name: 'Vue' })
Effect API
vue-demi provides the effect function which is part of the reactivity system in Vue 3 and is made available for Vue 2 through this package. It allows you to run side effects when reactive data changes.
import { effect } from 'vue-demi'
effect(() => {
console.log('This will run when reactive state changes')
})
This package is a plugin for Vue 2 that provides the Vue 3 Composition API. It is similar to vue-demi in that it allows developers to use Vue 3 features in Vue 2 applications, but it does not provide the same automatic compatibility layer for libraries to support both Vue 2 and Vue 3.
vue2-helpers is a set of helper functions for Vue 2 that aim to bring some of the Vue 3 functionality to Vue 2. While it provides similar bridging functionality, it is not as comprehensive as vue-demi and is more focused on specific helpers rather than a full compatibility layer.
Vue Demi (half in French) is a developing utility
allows you to write Universal Vue Libraries for Vue 2 & 3
See more details in this blog post
🚧 It's experimental, yet.
Install this as your plugin's dependency:
npm i vue-demi
# or
yarn add vue-demi
{
"dependencies": {
"vue-demi": "latest"
}
}
Import everything related to Vue from it, it will redirect to vue@2
@vue/composition-api
or vue@next
based on users' environments.
import { ref, reactive, defineComponent } from 'vue-demi'
Publish your plugin and all is done!
See examples.
See the blog post.
npx vue-demi-fix
MIT License © 2020 Anthony Fu
FAQs
Unknown package
The npm package vue-demi receives a total of 4,229,228 weekly downloads. As such, vue-demi popularity was classified as popular.
We found that vue-demi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.