From e1344e7c914be1acbf50d452a42cf7a005e2c8e4 Mon Sep 17 00:00:00 2001 From: hooray <304327508@qq.com> Date: Mon, 2 May 2022 16:45:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96unplugin-auto-import=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 2 +- .gitignore | 1 + auto-import-eslint-config.js | 56 ------------------------------------ vite/plugins/auto-import.js | 15 +++++++++- 4 files changed, 16 insertions(+), 58 deletions(-) delete mode 100644 auto-import-eslint-config.js diff --git a/.eslintrc.js b/.eslintrc.js index 43c20ae..eab2aba 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,7 +15,7 @@ module.exports = { 'plugin:vue/vue3-recommended', 'plugin:vue/vue3-strongly-recommended', 'eslint:recommended', - './auto-import-eslint-config.js' + './.eslintrc-auto-import.json' ], parser: 'vue-eslint-parser', parserOptions: { diff --git a/.gitignore b/.gitignore index b54654c..c66a0a6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ node_modules dist* dist-ssr *.local +.eslintrc-auto-import.json public/icons src/assets/sprites/*.* diff --git a/auto-import-eslint-config.js b/auto-import-eslint-config.js deleted file mode 100644 index 51dea85..0000000 --- a/auto-import-eslint-config.js +++ /dev/null @@ -1,56 +0,0 @@ -module.exports = { - globals: { - // lifecycle - onActivated: 'readonly', - onBeforeMount: 'readonly', - onBeforeUnmount: 'readonly', - onBeforeUpdate: 'readonly', - onDeactivated: 'readonly', - onErrorCaptured: 'readonly', - onMounted: 'readonly', - onServerPrefetch: 'readonly', - onUnmounted: 'readonly', - onUpdated: 'readonly', - // reactivity - computed: 'readonly', - customRef: 'readonly', - isReadonly: 'readonly', - isRef: 'readonly', - markRaw: 'readonly', - reactive: 'readonly', - readonly: 'readonly', - ref: 'readonly', - shallowReactive: 'readonly', - shallowReadonly: 'readonly', - shallowRef: 'readonly', - toRaw: 'readonly', - toRef: 'readonly', - toRefs: 'readonly', - triggerRef: 'readonly', - unref: 'readonly', - watch: 'readonly', - watchEffect: 'readonly', - // component - defineComponent: 'readonly', - defineAsyncComponent: 'readonly', - getCurrentInstance: 'readonly', - h: 'readonly', - inject: 'readonly', - nextTick: 'readonly', - provide: 'readonly', - useCssModule: 'readonly', - // other - defineProps: 'readonly', - defineEmits: 'readonly', - defineExpose: 'readonly', - withDefaults: 'readonly', - // vue-router - useRoute: 'readonly', - useRouter: 'readonly', - // element plus - ElMessage: 'readonly', - ElNotification: 'readonly', - ElMessageBox: 'readonly', - ElLoading: 'readonly' - } -} diff --git a/vite/plugins/auto-import.js b/vite/plugins/auto-import.js index 3bead4f..837eaa0 100644 --- a/vite/plugins/auto-import.js +++ b/vite/plugins/auto-import.js @@ -5,8 +5,21 @@ export default function createAutoImport() { return autoImport({ imports: [ 'vue', - 'vue-router' + 'vue-router', + { + 'vue': [ + 'defineProps', + 'defineEmits', + 'defineExpose', + 'withDefaults' + ] + } ], + eslintrc: { + enabled: true, + filepath: './.eslintrc-auto-import.json', + globalsPropValue: true + }, resolvers: [ ElementPlusResolver() ],