Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit b56f029

Browse files
committed
refactor: 引入 unplugin-auto-import,减少重复性 Vue 函数引入
避免在每个 Vue 组件中都重复性的去声明 ref 等函数
1 parent b2aa711 commit b56f029

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+302
-63
lines changed

.eslintrc-auto-import.json

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"globals": {
3+
"Component": true,
4+
"ComponentPublicInstance": true,
5+
"ComputedRef": true,
6+
"EffectScope": true,
7+
"ExtractDefaultPropTypes": true,
8+
"ExtractPropTypes": true,
9+
"ExtractPublicPropTypes": true,
10+
"InjectionKey": true,
11+
"PropType": true,
12+
"Ref": true,
13+
"VNode": true,
14+
"WritableComputedRef": true,
15+
"computed": true,
16+
"createApp": true,
17+
"customRef": true,
18+
"defineAsyncComponent": true,
19+
"defineComponent": true,
20+
"effectScope": true,
21+
"getCurrentInstance": true,
22+
"getCurrentScope": true,
23+
"h": true,
24+
"inject": true,
25+
"isProxy": true,
26+
"isReactive": true,
27+
"isReadonly": true,
28+
"isRef": true,
29+
"markRaw": true,
30+
"nextTick": true,
31+
"onActivated": true,
32+
"onBeforeMount": true,
33+
"onBeforeRouteLeave": true,
34+
"onBeforeRouteUpdate": true,
35+
"onBeforeUnmount": true,
36+
"onBeforeUpdate": true,
37+
"onDeactivated": true,
38+
"onErrorCaptured": true,
39+
"onMounted": true,
40+
"onRenderTracked": true,
41+
"onRenderTriggered": true,
42+
"onScopeDispose": true,
43+
"onServerPrefetch": true,
44+
"onUnmounted": true,
45+
"onUpdated": true,
46+
"provide": true,
47+
"reactive": true,
48+
"readonly": true,
49+
"ref": true,
50+
"resolveComponent": true,
51+
"shallowReactive": true,
52+
"shallowReadonly": true,
53+
"shallowRef": true,
54+
"toRaw": true,
55+
"toRef": true,
56+
"toRefs": true,
57+
"toValue": true,
58+
"triggerRef": true,
59+
"unref": true,
60+
"useAttrs": true,
61+
"useCssModule": true,
62+
"useCssVars": true,
63+
"useLink": true,
64+
"useRoute": true,
65+
"useRouter": true,
66+
"useSlots": true,
67+
"watch": true,
68+
"watchEffect": true,
69+
"watchPostEffect": true,
70+
"watchSyncEffect": true
71+
}
72+
}

.eslintrc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ module.exports = {
1818
'node': true,
1919
'vue/setup-compiler-macros': true,
2020
},
21-
plugins: ['@typescript-eslint'],
21+
plugins: ['vue', '@typescript-eslint'],
2222
extends: [
2323
// Airbnb JavaScript Style Guide https://github.com/airbnb/javascript
2424
'airbnb-base',
25+
'plugin:vue/vue3-essential', // vue3语法规则
2526
'plugin:@typescript-eslint/recommended',
2627
'plugin:import/recommended',
2728
'plugin:import/typescript',
2829
'plugin:vue/vue3-recommended',
2930
'plugin:prettier/recommended',
31+
'./.eslintrc-auto-import.json',
3032
],
3133
settings: {
3234
'import/resolver': {

config/vite.config.base.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@ import { resolve } from 'path';
22
import { defineConfig } from 'vite';
33
import vue from '@vitejs/plugin-vue';
44
import vueJsx from '@vitejs/plugin-vue-jsx';
5+
import AutoImport from 'unplugin-auto-import/vite';
56
import svgLoader from 'vite-svg-loader';
67
// import configArcoStyleImportPlugin from './plugin/arcoStyleImport';
78

89
export default defineConfig({
910
plugins: [
1011
vue(),
1112
vueJsx(),
13+
AutoImport({
14+
// 自动导入vue相关函数,如: ref、reactive、toRef等
15+
imports: ['vue', 'vue-router'],
16+
dts: 'src/auto-import.d.ts',
17+
eslintrc: {
18+
// 改为 true 用于生成 eslint 配置(生成后改回 false,避免重复生成消耗)
19+
enabled: false,
20+
},
21+
}),
1222
svgLoader({ svgoConfig: {} }),
1323
// configArcoStyleImportPlugin(),
1424
],
@@ -41,7 +51,7 @@ export default defineConfig({
4151
less: {
4252
modifyVars: {
4353
hack: `true; @import (reference) "${resolve(
44-
'src/assets/style/breakpoint.less'
54+
'src/assets/style/breakpoint.less',
4555
)}";`,
4656
},
4757
javascriptEnabled: true,

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"stylelint-config-standard": "^35.0.0",
9999
"stylelint-order": "^6.0.4",
100100
"typescript": "^5.3.3",
101+
"unplugin-auto-import": "^0.17.3",
101102
"unplugin-vue-components": "^0.26.0",
102103
"vite": "^4.5.1",
103104
"vite-plugin-compression": "^0.5.1",

0 commit comments

Comments
 (0)