-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
92 lines (89 loc) · 2.32 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* @Author: along
* @Description: viteConfig
* @Date: 2023-08-30 13:22:11
* @LastEditors: along
* @LastEditTime: 2024-05-08 15:48:19
* @FilePath: /cxy-v3-template/vite.config.ts
*/
import path from 'node:path';
import {defineConfig, loadEnv, splitVendorChunkPlugin} from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import AutoImport from 'unplugin-auto-import/vite';
import commpressPlugin from 'vite-plugin-compression';
import Components from 'unplugin-vue-components/vite';
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
const config = loadEnv(mode, __dirname);
console.log(config);
return {
plugins: [
vue(),
vueJsx(),
AutoImport({
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
imports: ['vue', 'pinia', 'vue-router'],
// 调整自动引入的文件位置
dts: './auto-import.d.ts',
// 解决自动引入eslint报错问题 需要在eslintrc的extend选项中引入
eslintrc: {
enabled: true,
// 配置文件的位置
filepath: './.eslintrc-auto-import.json',
globalsPropValue: true,
},
// 自动导入element
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
commpressPlugin({
verbose: true, // 默认即可
disable: false, // 开启压缩(不禁用),默认即可
deleteOriginFile: false, // 删除源文件
threshold: 1, // 压缩前最小文件大小
algorithm: 'gzip', // 压缩算法
ext: '.gz', // 文件类型
}),
splitVendorChunkPlugin(),
],
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true,
},
},
},
server: {
host: '0.0.0.0',
port: config.VITE_APP_PORT,
open: true,
},
build: {
chunkSizeWarningLimit: 2000,
rollupOptions: {
output: {
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
},
},
esbuild: {
pure: ['console.log'],
minify: true,
},
resolve: {
alias: {
'~': path.resolve(__dirname, './src'),
'@': path.resolve(__dirname, './src'),
},
},
define: {
__APP_ENV__: JSON.stringify(config.VITE_APP_API_BASE_URL),
},
};
});