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

Commit

Permalink
refactor: 引入 unplugin-auto-import,减少重复性 Vue 函数引入
Browse files Browse the repository at this point in the history
避免在每个 Vue 组件中都重复性的去声明 ref 等函数
  • Loading branch information
Charles7c committed Jan 7, 2024
1 parent b2aa711 commit b56f029
Show file tree
Hide file tree
Showing 55 changed files with 302 additions and 63 deletions.
72 changes: 72 additions & 0 deletions .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"globals": {
"Component": true,
"ComponentPublicInstance": true,
"ComputedRef": true,
"EffectScope": true,
"ExtractDefaultPropTypes": true,
"ExtractPropTypes": true,
"ExtractPublicPropTypes": true,
"InjectionKey": true,
"PropType": true,
"Ref": true,
"VNode": true,
"WritableComputedRef": true,
"computed": true,
"createApp": true,
"customRef": true,
"defineAsyncComponent": true,
"defineComponent": true,
"effectScope": true,
"getCurrentInstance": true,
"getCurrentScope": true,
"h": true,
"inject": true,
"isProxy": true,
"isReactive": true,
"isReadonly": true,
"isRef": true,
"markRaw": true,
"nextTick": true,
"onActivated": true,
"onBeforeMount": true,
"onBeforeRouteLeave": true,
"onBeforeRouteUpdate": true,
"onBeforeUnmount": true,
"onBeforeUpdate": true,
"onDeactivated": true,
"onErrorCaptured": true,
"onMounted": true,
"onRenderTracked": true,
"onRenderTriggered": true,
"onScopeDispose": true,
"onServerPrefetch": true,
"onUnmounted": true,
"onUpdated": true,
"provide": true,
"reactive": true,
"readonly": true,
"ref": true,
"resolveComponent": true,
"shallowReactive": true,
"shallowReadonly": true,
"shallowRef": true,
"toRaw": true,
"toRef": true,
"toRefs": true,
"toValue": true,
"triggerRef": true,
"unref": true,
"useAttrs": true,
"useCssModule": true,
"useCssVars": true,
"useLink": true,
"useRoute": true,
"useRouter": true,
"useSlots": true,
"watch": true,
"watchEffect": true,
"watchPostEffect": true,
"watchSyncEffect": true
}
}
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ module.exports = {
'node': true,
'vue/setup-compiler-macros': true,
},
plugins: ['@typescript-eslint'],
plugins: ['vue', '@typescript-eslint'],
extends: [
// Airbnb JavaScript Style Guide https://github.com/airbnb/javascript
'airbnb-base',
'plugin:vue/vue3-essential', // vue3语法规则
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:vue/vue3-recommended',
'plugin:prettier/recommended',
'./.eslintrc-auto-import.json',
],
settings: {
'import/resolver': {
Expand Down
12 changes: 11 additions & 1 deletion config/vite.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import { resolve } from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import AutoImport from 'unplugin-auto-import/vite';
import svgLoader from 'vite-svg-loader';
// import configArcoStyleImportPlugin from './plugin/arcoStyleImport';

export default defineConfig({
plugins: [
vue(),
vueJsx(),
AutoImport({
// 自动导入vue相关函数,如: ref、reactive、toRef等
imports: ['vue', 'vue-router'],
dts: 'src/auto-import.d.ts',
eslintrc: {
// 改为 true 用于生成 eslint 配置(生成后改回 false,避免重复生成消耗)
enabled: false,
},
}),
svgLoader({ svgoConfig: {} }),
// configArcoStyleImportPlugin(),
],
Expand Down Expand Up @@ -41,7 +51,7 @@ export default defineConfig({
less: {
modifyVars: {
hack: `true; @import (reference) "${resolve(
'src/assets/style/breakpoint.less'
'src/assets/style/breakpoint.less',
)}";`,
},
javascriptEnabled: true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"stylelint-config-standard": "^35.0.0",
"stylelint-order": "^6.0.4",
"typescript": "^5.3.3",
"unplugin-auto-import": "^0.17.3",
"unplugin-vue-components": "^0.26.0",
"vite": "^4.5.1",
"vite-plugin-compression": "^0.5.1",
Expand Down
Loading

0 comments on commit b56f029

Please sign in to comment.