Installations
npm install vue-demi
Developer
antfu
Developer Guide
Module System
CommonJS, ESM
Min. Node Version
>=12
Typescript Support
Yes
Node Version
20.12.2
NPM Version
10.5.0
Statistics
3,014 Stars
210 Commits
158 Forks
27 Watching
1 Branches
60 Contributors
Updated on 26 Nov 2024
Bundle Size
822.00 B
Minified
389.00 B
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
307,796,118
Last day
-1%
925,169
Compared to previous day
Last week
1.4%
4,730,602
Compared to previous week
Last month
12.6%
19,868,058
Compared to previous month
Last year
104.2%
185,136,388
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
2
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
Strategies
<=2.6
: exports fromvue
+@vue/composition-api
with plugin auto installing.2.7
: exports fromvue
(Composition API is built-in in Vue 2.7).>=3.0
: exports fromvue
, with polyfill of Vue 2'sset
anddel
API.
Usage
Install this as your plugin's dependency:
1npm i vue-demi 2# or 3yarn add vue-demi 4# or 5pnpm i vue-demi
Add vue
and @vue/composition-api
to your plugin's peer dependencies to specify what versions you support.
1{ 2 "dependencies": { 3 "vue-demi": "latest" 4 }, 5 "peerDependencies": { 6 "@vue/composition-api": "^1.0.0-rc.1", 7 "vue": "^2.0.0 || >=3.0.0" 8 }, 9 "peerDependenciesMeta": { 10 "@vue/composition-api": { 11 "optional": true 12 } 13 }, 14 "devDependencies": { 15 "vue": "^3.0.0" // or "^2.6.0" base on your preferred working environment 16 }, 17}
Import everything related to Vue from it, it will redirect to vue@2
+ @vue/composition-api
or vue@3
based on users' environments.
1import { ref, reactive, defineComponent } from 'vue-demi'
Publish your plugin and all is done!
When using with Vite, you will need to opt-out the pre-bundling to get
vue-demi
work properly by1// vite.config.js 2export default defineConfig({ 3 optimizeDeps: { 4 exclude: ['vue-demi'] 5 } 6})
Extra APIs
Vue Demi
provides extra APIs to help distinguish users' environments and to do some version-specific logic.
isVue2
isVue3
1import { isVue2, isVue3 } from 'vue-demi' 2 3if (isVue2) { 4 // Vue 2 only 5} else { 6 // Vue 3 only 7}
Vue2
To avoid bringing in all the tree-shakable modules, we provide a Vue2
export to support access to Vue 2's global API. (See #41.)
1import { Vue2 } from 'vue-demi' 2 3if (Vue2) { 4 Vue2.config.ignoredElements.push('x-foo') 5}
install()
Composition API in Vue 2 is provided as a plugin and needs to be installed on the Vue instance before using. Normally, vue-demi
will try to install it automatically. For some usages where you might need to ensure the plugin gets installed correctly, the install()
API is exposed to as a safe version of Vue.use(CompositionAPI)
. install()
in the Vue 3 environment will be an empty function (no-op).
1import { install } from 'vue-demi' 2 3install()
CLI
Manually Switch Versions
To explicitly switch the redirecting version, you can use these commands in your project's root.
1npx vue-demi-switch 2 2# or 3npx vue-demi-switch 3
Package Aliasing
If you would like to import vue
under an alias, you can use the following command
1npx vue-demi-switch 2 vue2 2# or 3npx vue-demi-switch 3 vue3
Then vue-demi
will redirect APIs from the alias name you specified, for example:
1import * as Vue from 'vue3' 2 3var isVue2 = false 4var isVue3 = true 5var Vue2 = undefined 6 7export * from 'vue3' 8export { 9 Vue, 10 Vue2, 11 isVue2, 12 isVue3, 13}
Auto Fix
If the postinstall
hook doesn't get triggered or you have updated the Vue version, try to run the following command to resolve the redirecting.
1npx vue-demi-fix
Isomorphic Testings
You can support testing for both versions by adding npm alias in your dev dependencies. For example:
1{ 2 "scripts": { 3 "test:2": "vue-demi-switch 2 vue2 && jest", 4 "test:3": "vue-demi-switch 3 && jest", 5 }, 6 "devDependencies": { 7 "vue": "^3.0.0", 8 "vue2": "npm:vue@2" 9 }, 10}
or
1{ 2 "scripts": { 3 "test:2": "vue-demi-switch 2 && jest", 4 "test:3": "vue-demi-switch 3 vue3 && jest", 5 }, 6 "devDependencies": { 7 "vue": "^2.6.0", 8 "vue3": "npm:vue@3" 9 }, 10}
Examples
See examples.
Who is using this?
- VueUse - Collection of Composition API utils
- @vue/apollo-composable - Apollo GraphQL functions for Vue Composition API
- vuelidate - Simple, lightweight model-based validation
- vue-composition-test-utils - Simple vue composition api unit test utilities
- vue-use-stripe - Stripe Elements wrapper for Vue.js
- @opd/g2plot-vue - G2plot for vue
- vue-echarts - Vue.js component for Apache ECharts.
- fluent-vue - Vue.js integration for Fluent.js - JavaScript implementation of Project Fluent
- vue-datatable-url-sync - Synchronize datatable options and filters with the url to keep user preference even after refresh or navigation
- vue-insta-stories - Instagram stories in your vue projects.
- vue-tiny-validate - Tiny Vue Validate Composition
- v-perfect-signature - Pressure-sensitive signature drawing for Vue 2 and 3
- vue-winbox - A wrapper component for WinBox.js that adds the ability to mount Vue components.
- vue-word-highlighter - The word highlighter library for Vue 2 and Vue 3
- vue-chart-3 - Vue.js component for Chart.js
- json-editor-vue - JSON editor & viewer for Vue 2 and 3.
- kidar-echarts - A simpler echarts component for Vue 2 and 3.
- vue3-sketch-ruler - The zoom operation used for page presentation for Vue 2 and 3( Replace render function with template )
- vue-rough-notation - RoughNotation wrapper component for Vue 2 and 3.
- vue-request - Vue composition API for data fetching, supports SWR, polling, error retry, cache request, pagination, etc.
- vue3-lazyload - A vue3.x image lazyload plugin.
- vue-codemirror6 - CodeMirror6 component for Vue2 and 3.
- @tanstack/vue-query - TanStack Query for Vue.
open a PR to add your library ;)
Underhood
See the blog post.
License
MIT License © 2020 Anthony Fu
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 14/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:45: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:62: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:65: update your workflow using https://app.stepsecurity.io/secureworkflow/vueuse/vue-demi/test.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:69
- Info: 0 out of 8 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Score
3.8
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to vue-demi
v-code-diff
template component for vue-demi, can dev and build
sy-assistant
本项目基于[Vue-demi](https://github.com/vue-demi/vue-demi),可以同时兼容Vue2和Vue3。
vue-inbrowser-compiler-demi
use this with vue-inbrowser-compiler to compile for vue2 or vue3
universal-panduan-oss
- Building Universal Vue Libraries panduan for Vue 2 & 3 - Using vue-demi but you don't need to write "render" function, "template" and "tsx" are supported!