Skip to content

Commit e80c60b

Browse files
committed
feat: add Vue2 export and deprecate Vue
1 parent e9639af commit e80c60b

File tree

9 files changed

+45
-9
lines changed

9 files changed

+45
-9
lines changed

.github/test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
22
const { join } = require('path')
3-
const { execSync, exec } = require('child_process')
3+
const { execSync } = require('child_process')
44

55
const DIR = '../vue-demi-test'
66

@@ -24,9 +24,16 @@ if (!cjs.includes(`exports.isVue2 = ${isVue2}`)) {
2424
process.exit(1)
2525
}
2626

27-
const value = execSync('node -e "console.log(require(\'vue-demi\').isVue2)"', { cwd: DIR }).toString().trim()
27+
const isVue2 = execSync('node -e "console.log(require(\'vue-demi\').isVue2)"', { cwd: DIR }).toString().trim()
2828

29-
if (value !== `${isVue2}`) {
30-
console.log("eval", value)
29+
if (isVue2 !== `${isVue2}`) {
30+
console.log("isVue2", isVue2)
31+
process.exit(1)
32+
}
33+
34+
const hasVue2 = execSync('node -e "console.log(require(\'vue-demi\').Vue2 !== undefined)"', { cwd: DIR }).toString().trim()
35+
36+
if (hasVue2 !== `${isVue2}`) {
37+
console.log("hasVue2", hasVue2)
3138
process.exit(1)
3239
}

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,26 @@ if (isVue2) {
6161
}
6262
```
6363

64+
### `Vue2`
65+
66+
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](https://github.com/vueuse/vue-demi/issues/41).)
67+
68+
```ts
69+
import { Vue2 } from 'vue-demi'
70+
71+
if (Vue2) {
72+
Vue2.config.ignoredElements.push('x-foo')
73+
}
74+
```
75+
6476
### `install()`
6577

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

6880
```ts
69-
import Vue from 'vue'
70-
import { install } from 'vue-demi'
81+
import { Vue2, install } from 'vue-demi'
7182

72-
install(Vue)
83+
install(Vue2)
7384
```
7485

7586
## CLI
@@ -101,10 +112,12 @@ import * as Vue from 'vue3'
101112

102113
var isVue2 = false
103114
var isVue3 = true
115+
var Vue2 = undefined
104116

105117
export * from 'vue3'
106118
export {
107119
Vue,
120+
Vue2,
108121
isVue2,
109122
isVue3,
110123
}

lib/index.iife.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
VueDemi.isVue3 = false
1616
VueDemi.install = function (){}
1717
VueDemi.Vue = Vue
18+
VueDemi.Vue2 = Vue
1819
VueDemi.version = Vue.version
1920
} else {
2021
console.error(
@@ -29,6 +30,7 @@
2930
VueDemi.isVue3 = true
3031
VueDemi.install = function (){}
3132
VueDemi.Vue = Vue
33+
VueDemi.Vue2 = undefined
3234
VueDemi.version = Vue.version
3335
VueDemi.set = function(target, key, val) {
3436
if (Array.isArray(target)) {

lib/v2/index.cjs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Object.keys(VueCompositionAPI).forEach(function(key) {
1818
})
1919

2020
exports.Vue = Vue
21+
exports.Vue2 = Vue
2122
exports.isVue2 = true
2223
exports.isVue3 = false
2324
exports.install = install

lib/v2/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import Vue from 'vue'
22
declare const isVue2: boolean
33
declare const isVue3: boolean
4+
declare const Vue2: Vue
45
declare const version: string
56
declare const install: (vue?: Vue) => void
7+
/** @deprecated */
8+
declare const V: Vue
69

710
export * from '@vue/composition-api'
811
export {
9-
Vue,
12+
V as Vue,
13+
Vue2,
1014
isVue2,
1115
isVue3,
1216
version,

lib/v2/index.esm.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ install(Vue)
1111

1212
var isVue2 = true
1313
var isVue3 = false
14+
var Vue2 = Vue
1415
var version = Vue.version
1516

1617
/**VCA-EXPORTS**/
@@ -19,6 +20,7 @@ export * from '@vue/composition-api'
1920

2021
export {
2122
Vue,
23+
Vue2,
2224
isVue2,
2325
isVue3,
2426
version,

lib/v3/index.cjs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ exports.del = function(target, key) {
2323
}
2424

2525
exports.Vue = Vue
26+
exports.Vue2 = undefined
2627
exports.isVue2 = false
2728
exports.isVue3 = true
2829
exports.install = function(){}

lib/v3/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import * as Vue from 'vue'
22
declare const isVue2: boolean
33
declare const isVue3: boolean
4+
declare const Vue2: any
45
declare const install: (vue?: any) => void
6+
/** @deprecated */
7+
declare const V: Vue
58

69
export function set<T>(target: any, key: any, val: T): T
710
export function del(target: any, key: any)
811

912
export * from 'vue'
1013
export {
11-
Vue,
14+
V as Vue,
15+
Vue2,
1216
isVue2,
1317
isVue3,
1418
install,

lib/v3/index.esm.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as Vue from 'vue'
22

33
var isVue2 = false
44
var isVue3 = true
5+
var Vue2 = undefined
56

67
function install() {}
78

@@ -26,6 +27,7 @@ export function del(target, key) {
2627
export * from 'vue'
2728
export {
2829
Vue,
30+
Vue2,
2931
isVue2,
3032
isVue3,
3133
install,

0 commit comments

Comments
 (0)