一、安装
1 |
npm i -D unplugin-auto-import |
二、配置vite.config.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// 按需自动导入 import AutoImport from 'unplugin-auto-import/vite' import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' export default ({ mode }) => { return defineConfig({ ... plugins: [ ... AutoImport({ resolvers: [ ElementPlusResolver() ], dts: './auto-imports.d.ts', eslintrc: { enabled: true, filepath: './.eslintrc-auto-import.json', globalsPropValue: true } }) ] }) |
三、添加.eslintrc-auto-import.json
1 2 3 |
{ "globals": {} } |
四、配置.eslintrc
1 2 3 4 5 6 7 |
{ ... "extends": [ ... "./.eslintrc-auto-import.json" ] } |
五、配置tsconfig.json
1 2 3 4 5 |
{ ... "include": ["./auto-imports.d.ts"] } |