Skip to content

Commit 3615027

Browse files
committed
chore(examples): add vue2 and vue3 playground
1 parent 2d33372 commit 3615027

File tree

11 files changed

+1456
-1633
lines changed

11 files changed

+1456
-1633
lines changed

build/vite-vue2.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import path from 'path';
2+
import { defineConfig } from 'vite';
3+
import { createVuePlugin } from 'vite-plugin-vue2';
4+
5+
export default defineConfig({
6+
clearScreen: false,
7+
resolve: {
8+
alias: {
9+
'vue-request': path.resolve(__dirname, '../src/index.ts'),
10+
vue: 'vue2',
11+
},
12+
},
13+
plugins: [createVuePlugin()],
14+
});

build/vite.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ export default defineConfig({
88
resolve: {
99
alias: {
1010
'vue-request': path.resolve(__dirname, '../src/index.ts'),
11+
vue: 'vue3',
1112
},
1213
},
1314
plugins: [vue(), vueJsx()],
14-
optimizeDeps: {
15-
exclude: ['vue-demi'],
16-
},
1715
});

examples/vue2/App.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<div>
3+
<button @click="() => run()">run</button>
4+
<br />
5+
{{ loading ? 'loading...' : data }}
6+
</div>
7+
</template>
8+
9+
<script>
10+
import { defineComponent } from '@vue/composition-api';
11+
import { useRequest } from 'vue-request';
12+
function testService() {
13+
return new Promise(resolve => {
14+
setTimeout(() => {
15+
resolve('success');
16+
}, 1000);
17+
});
18+
}
19+
20+
export default defineComponent({
21+
setup() {
22+
const { run, data, loading } = useRequest(testService);
23+
return {
24+
run,
25+
data,
26+
loading,
27+
};
28+
},
29+
});
30+
</script>

examples/vue2/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
7+
<title>vue-request</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="./main.js"></script>
12+
<!-- built files will be auto injected -->
13+
</body>
14+
</html>

examples/vue2/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import VCA, { createApp, h } from '@vue/composition-api';
2+
import Vue from 'vue2';
3+
4+
import App from './App.vue';
5+
6+
Vue.use(VCA);
7+
8+
const app = createApp({
9+
render: () => h(App),
10+
});
11+
12+
app.mount('#app');

example/App.tsx renamed to examples/vue3/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineComponent } from 'vue';
21
import { useRequest } from 'vue-request';
2+
import { defineComponent } from 'vue3';
33

44
function testService() {
55
return new Promise<string>(resolve => {
File renamed without changes.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { createApp } from 'vue';
1+
import { createApp } from 'vue3';
2+
23
import App from './App';
34

45
createApp(App).mount('#app');

package.json

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@
3030
],
3131
"scripts": {
3232
"build": "yarn clean && rollup --config ./build/rollup.config.js",
33-
"dev": "yarn vite ./example",
33+
"dev": "vue-demi-switch 3 vue3 && vite --config ./build/vite.config.ts ./examples/vue3",
34+
"dev:2": "vue-demi-switch 2 vue2 && vite --config ./build/vite-vue2.config.ts ./examples/vue2",
35+
"test": "vue-demi-switch 3 vue3 && jest --coverage",
36+
"test:2": "vue-demi-switch 2 vue2 && jest --coverage",
3437
"clean": "rimraf dist/*",
35-
"test": "jest --coverage",
3638
"publishing": "np",
3739
"changelog": "standard-version && standard-version -i CHANGELOG.zh-CN.md -o CHANGELOG.zh-CN.md",
3840
"release": "yarn build && yarn publishing",
3941
"lint": "eslint -c ./.eslintrc.js './{src,scripts,build}/**/*.{js,ts,tsx}'",
4042
"format": "prettier -w '**/*.ts?(x)'",
41-
"vite": "vite --config ./build/vite.config.ts"
43+
"postinstall": "patch-package"
4244
},
4345
"husky": {
4446
"hooks": {
@@ -71,30 +73,31 @@
7173
"@rollup/plugin-babel": "^5.2.1",
7274
"@rollup/plugin-commonjs": "^16.0.0",
7375
"@rollup/plugin-node-resolve": "^10.0.0",
74-
"@types/jest": "^26.0.15",
76+
"@types/jest": "^27.4.0",
7577
"@types/mockjs": "^1.0.3",
78+
"@types/node": "^17.0.16",
7679
"@typescript-eslint/eslint-plugin": "^4.8.2",
7780
"@typescript-eslint/parser": "^4.8.2",
7881
"@vitejs/plugin-vue": "^1.2.1",
7982
"@vitejs/plugin-vue-jsx": "^1.1.3",
8083
"@vue/babel-plugin-jsx": "^1.0.0-rc.3",
8184
"@vue/compiler-sfc": "^3.0.6",
82-
"@vue/test-utils": "^2.0.0-beta.8",
85+
"@vue/composition-api": "^1.4.6",
8386
"axios": "^0.21.1",
84-
"babel-jest": "^26.6.0",
87+
"babel-jest": "^27.5.0",
8588
"eslint": "^7.14.0",
8689
"eslint-config-prettier": "^6.15.0",
8790
"eslint-plugin-prettier": "^3.1.4",
8891
"eslint-plugin-simple-import-sort": "^7.0.0",
8992
"eslint-plugin-vue": "^7.0.0-0",
9093
"fetch-mock": "^9.10.7",
9194
"husky": "^4.3.0",
92-
"jest": "^26.6.0",
95+
"jest": "^27.5.0",
9396
"jest-environment-jsdom-global": "^2.0.4",
9497
"lint-staged": "^10.5.2",
9598
"mockjs": "^1.1.0",
96-
"node-fetch": "^2.6.1",
9799
"np": "^7.0.0",
100+
"patch-package": "^6.4.7",
98101
"prettier": "^2.2.0",
99102
"rimraf": "^3.0.2",
100103
"rollup": "^2.33.1",
@@ -103,11 +106,13 @@
103106
"simple-git": "^2.21.0",
104107
"sort-package-json": "^1.50.0",
105108
"standard-version": "^9.1.1",
106-
"ts-jest": "^26.4.1",
109+
"ts-jest": "^27.1.3",
107110
"typescript": "^4.0.5",
108111
"vite": "^2.1.5",
109-
"vue": "^3.0.2",
110-
"vue2": "npm:vue@2"
112+
"vite-plugin-vue2": "^1.9.2",
113+
"vue-template-compiler": "^2.6.14",
114+
"vue2": "npm:vue@2",
115+
"vue3": "npm:vue@3"
111116
},
112117
"peerDependencies": {
113118
"@vue/composition-api": "^1.0.0-rc.1",

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
"declaration": true,
1313
"declarationDir": "dist/types",
1414
"baseUrl": "./",
15-
"types": ["jest", "@vue/test-utils"],
15+
"types": ["jest", "node"],
1616
"paths": {
1717
"vue-request": ["src/index.ts"]
1818
}
1919
},
20-
"include": ["src", "example", "**/__tests__/**/*"],
20+
"include": ["src", "examples", "**/__tests__/**/*"],
2121
"exclude": ["node_modules", "dist"]
2222
}

0 commit comments

Comments
 (0)