-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
113 lines (110 loc) · 3.08 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* eslint-disable */
import { fileURLToPath, URL } from 'node:url'
import react from '@vitejs/plugin-react'
import AutoImport from 'unplugin-auto-import/vite'
import AhooksResolver from 'unplugin-auto-import-ahooks'
import AntdResolver from 'unplugin-auto-import-antd'
import { defineConfig, loadEnv } from 'vite'
import ViteCompression from 'vite-plugin-compression'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// https://vitejs.dev/config/
export default ({ mode }) => {
console.log('mode', loadEnv(mode, process.cwd()).VITE_BASE_URL) //127.0.0.1:9000/api
return defineConfig({
plugins: [
react(),
AutoImport({
dts: '@types/auto-imports.d.ts',
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
],
imports: [
'react',
'react-router-dom',
{
from: 'react',
imports: ['Suspense'],
},
{
from: 'use-immer',
imports: ['useImmer'],
},
{
from: '@ant-design/icons',
imports: [['default', 'AIcon']],
},
],
resolvers: [AntdResolver({ prefix: 'A' }), AhooksResolver()],
dirs: [
'src/api/**',
'src/components/**',
'src/hooks/**',
'src/layouts/*/index.tsx',
'src/providers/**',
'src/store/**',
],
}),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [fileURLToPath(new URL('./src/assets/svgs', import.meta.url))],
// 指定symbolId格式
symbolId: 'icon-[name]',
}),
ViteCompression({
filter: /\.(js|mjs|json|css|html|ttf|otf|svg)$/i,
algorithm: 'gzip',
threshold: 1024 * 5, // 5k以上压缩,
}),
],
//这里进行配置别名
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/styles/variables.scss" as *;`,
},
},
},
build: {
minify: 'terser',
terserOptions: {
compress: {
drop_console: true, // 是否过滤掉所有consol.log
drop_debugger: true,
},
},
reportCompressedSize: false,
chunkSizeWarningLimit: 1500,
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
manualChunks: {
react: ['react', 'react-dom', 'react-router-dom', 'zustand'],
antd: ['antd'],
},
},
},
},
base: '/',
server: {
host: '0.0.0.0',
port: 8080,
open: true,
proxy: {
'/api': {
target: '要代理的地址',
changeOrigin: true,
ws: true,
rewrite: (path: string) => path.replace(/^\/api/, ''),
},
},
},
})
}