-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
52 lines (49 loc) · 1.72 KB
/
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* eslint-disable import/no-extraneous-dependencies */
// 引入开发依赖导致的错误,不需要显示错误
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import eslintPlugin from 'vite-plugin-eslint';
// eslint-disable-next-line import/no-unresolved
import Components from 'unplugin-vue-components/vite';
import AutoImport from 'unplugin-auto-import/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
const path = require('path');
// unplugin-vue-components/vite 包的按需引入配置项
// https://www.npmjs.com/package/unplugin-vue-components
const ComponentsOptions = {
directoryAsNamespace: false,
// 设置为 true 能够为 volar 提供更好的支持
dts: true,
dirs: ['src/components'], // 配置需要默认导入的自定义组件文件夹,该文件夹下的所有组件都会自动 import
exclude: [/[\\/]node_modules[\\/]/, /[\\/]dist[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/],
// 以后组件库需要异步加载的就把解析器放 resolvers 数组里
resolvers: [ElementPlusResolver()],
// importPathTransform: (v) => {
// console.log(v);
// return v;
// },
};
export default defineConfig({
plugins: [
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
// 按需引入的插件
Components(ComponentsOptions),
// eslint 会检查 src 下的所有 .js 文件,所有 .vue 文件
eslintPlugin({
include: ['src/**/*.js', 'src/**/*.vue', 'src/*.js', 'src/*.vue'],
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'), // 处理全局别名
},
},
server: {
// vite 热更新,禁用或配置 HMR 连接
hmr: true,
port: 3000, // 端口号
},
});