All Projects → vueuse → Vue Demi

vueuse / Vue Demi

Licence: mit
🎩 Creates Universal Library for Vue 2 & 3

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Vue Demi

Vue Spotify
Spotify client built with vue.js / vuex
Stars: ✭ 407 (-25.18%)
Mutual labels:  vue2
Vue Drag Drop
A lightweight Vue wrapper that abstracts away the wonkier parts of the Drag and Drop Browser API
Stars: ✭ 444 (-18.38%)
Mutual labels:  vue2
Vue Star Rating
⭐️ A simple, highly customisable star rating component for Vue 2.x. / 3.x
Stars: ✭ 509 (-6.43%)
Mutual labels:  vue2
Fans
这是一个app(android/iOS)项目,但页面视图全部都用的是html5页,没有使用app的原生页面。 前端h5是基于mui + vue2 + vue-router2 + es6 + webpack2 + vuex + signalR 的前端webApp单页项目框架,项目可以直接在PC上运行html5页面。 app打包技术是用HBuilder IDE工具一键打包成APP。
Stars: ✭ 416 (-23.53%)
Mutual labels:  vue2
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (-20.22%)
Mutual labels:  vue2
Vue2 Calendar
vue 2.x calendar component
Stars: ✭ 477 (-12.32%)
Mutual labels:  vue2
Draggable Example
vue.draggable example
Stars: ✭ 395 (-27.39%)
Mutual labels:  vue2
Vuetron
A tool for testing and debugging your Vue + Vuex applications. 是一個可以幫助您 Vue.js 的項目測試及偵錯的工具, 也同時支持 Vuex及 Vue-Router.
Stars: ✭ 531 (-2.39%)
Mutual labels:  vue2
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (-18.57%)
Mutual labels:  vue2
Pixel Web
一个 Vue 微博客户端
Stars: ✭ 500 (-8.09%)
Mutual labels:  vue2
Vue2 blog
使用vue2.x + vue-cli +vue-router+ vuex + axios + mysql + express + pm2 + webpack+nginx构建的具有登录,注册,留言,用户发帖,用户评论等功能的SPA Blog。注意,注意,注意,后端API全部自己手写,很适合刚学习vue以及express的小伙伴学习,喜欢请Star鼓励一下我,谢谢!项目预览:
Stars: ✭ 417 (-23.35%)
Mutual labels:  vue2
Vue Datasource
A vue.js component to create dynamic tables
Stars: ✭ 420 (-22.79%)
Mutual labels:  vue2
Meal Prep
Source code for a 4-part series I wrote about Vue, Vue Router, Vuex and Vuetify
Stars: ✭ 496 (-8.82%)
Mutual labels:  vue2
D2 Admin Pm
基于 d2-admin的RBAC权限管理解决方案
Stars: ✭ 409 (-24.82%)
Mutual labels:  vue2
Stresstestplatform
基于Jmeter实现的在线压测和管理Jmx的平台。
Stars: ✭ 515 (-5.33%)
Mutual labels:  vue2
Vue2
【🔥Vue.js资讯📚】目前web前端开发非常火爆的框架;定时更新,欢迎 Star 一下。
Stars: ✭ 395 (-27.39%)
Mutual labels:  vue2
Vue Jstree
A Tree Plugin For Vue2.0+
Stars: ✭ 469 (-13.79%)
Mutual labels:  vue2
Vuelayers
Web map Vue components with the power of OpenLayers
Stars: ✭ 532 (-2.21%)
Mutual labels:  vue2
Vue Quasar Admin
Vue 2.0 admin-dashboard based on Quasar-Framework
Stars: ✭ 516 (-5.15%)
Mutual labels:  vue2
Dashboard
A dashboard scaffolding based on Vue.js 3.0 created by Vite.
Stars: ✭ 497 (-8.64%)
Mutual labels:  vue2


npm

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



Usage

Install this as your plugin's dependency:

npm i vue-demi
# or
yarn add vue-demi

Add vue and @vue/composition-api to your plugin's peer dependencies to specify what versions you support.

{
  "dependencies": {
    "vue-demi": "latest"
  },
  "peerDependencies": {
    "@vue/composition-api": "^1.0.0-beta.1",
    "vue": "^2.0.0 || >=3.0.0-rc.0"
  },
  "peerDependenciesMeta": {
    "@vue/composition-api": {
      "optional": true
    }
  },
  "devDependencies": {
    "vue": "^3.0.0" // or "^2.6.0" base on your preferred working environment
  },
}

Import everything related to Vue from it, it will redirect to [email protected] + @vue/composition-api or [email protected] based on users' environments.

import { ref, reactive, defineComponent } from 'vue-demi'

Publish your plugin and all is done!

Extra APIs

Vue Demi provides extra APIs to help distinguishing users' environments and to do some version-specific logics.

isVue2 isVue3

import { isVue2, isVue3 } from 'vue-demi'

if (isVue2) {
  // Vue 2 only
} else {
  // Vue 3 only
}

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.)

import { Vue2 } from 'vue-demi'

if (Vue2) {
  Vue2.config.ignoredElements.push('x-foo')
}

install()

Composition API in Vue 2 is provided as a plugin and need to install to Vue instance before using. Normally, vue-demi will try to install it automatically. For some usages that you might need to ensure the plugin get installed correctly, the install() API is exposed to as a safe version of Vue.use(CompositionAPI). install() in Vue 3 environment will be an empty function (no-op).

import { install } from 'vue-demi'

install()

CLI

Manually Switch Versions

To explicitly switch the redirecting version, you can use these commands in your project's root.

npx vue-demi-switch 2
# or
npx vue-demi-switch 3

Package Aliasing

If you would like to import vue under an alias, you can use the following command

npx vue-demi-switch 2 vue2
# or
npx vue-demi-switch 3 vue3

Then vue-demi will redirect APIs from the alias name you specified, for example:

import * as Vue from 'vue3'

var isVue2 = false
var isVue3 = true
var Vue2 = undefined

export * from 'vue3'
export {
  Vue,
  Vue2,
  isVue2,
  isVue3,
}

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.

npx vue-demi-fix

Isomorphic Testings

You can support testing for both versions by adding npm alias in your dev dependencies. For example:

{
  "scripts": {
    "test:2": "vue-demi-switch 2 vue2 && jest",
    "test:3": "vue-demi-switch 3 && jest",
  },
  "devDependencies": {
    "vue": "^3.0.0",
    "vue2": "npm:[email protected]"
  },
}

or

{
  "scripts": {
    "test:2": "vue-demi-switch 2 && jest",
    "test:3": "vue-demi-switch 3 vue3 && jest",
  },
  "devDependencies": {
    "vue": "^2.6.0",
    "vue3": "npm:[email protected]"
  },
}

Examples

See examples.

Who are using this?

open a PR to add your library ;)

Underhood

See the blog post.

License

MIT License © 2020 Anthony Fu

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].