-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
162 lines (160 loc) · 4.97 KB
/
vite.config.ts
File metadata and controls
162 lines (160 loc) · 4.97 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/// <reference types="vitest/config" />
import { resolve } from 'node:path';
import vue from '@vitejs/plugin-vue';
import UnoCSS from 'unocss/vite';
import AutoImport from 'unplugin-auto-import/vite';
import SvgComponent from 'unplugin-svg-component/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { defineConfig, loadEnv } from 'vite';
import svgLoader from 'vite-svg-loader';
// Configuring Vite: https://vitejs.dev/config
export default defineConfig(({ mode }) => {
const { VITE_PUBLIC_PATH } = loadEnv(mode, process.cwd(), '') as ImportMetaEnv;
return {
// Base public path when served in development or production
base: VITE_PUBLIC_PATH,
resolve: {
alias: {
// @ symbol points to src directory
'@': resolve(__dirname, 'src'),
// @@ symbol points to src/common directory
'@@': resolve(__dirname, 'src/common')
}
},
// Development server configuration
server: {
// Listen on all addresses
host: true,
// Port number
port: 3333,
// Exit if port is already in use
strictPort: false,
// Automatically open browser
open: true,
// Proxy configuration
proxy: {
'/dev': {
target: 'http://192.168.123.224:1031',
// Enable WebSocket proxy
ws: false,
// Change origin for CORS
changeOrigin: true,
rewrite: path => path.replace(/^\/dev/, '')
},
'/credit': {
target: 'https://api.deepgram.com/v1',
changeOrigin: true,
rewrite: path => path.replace(/^\/credit/, '')
}
},
// Enable CORS
cors: false,
// Warm up frequently used files for faster initial page load
warmup: {
clientFiles: [
'./src/layouts/**/*.*',
'./src/pinia/**/*.*',
'./src/router/**/*.*'
]
}
},
// Build configuration
build: {
// Custom Rollup bundling configuration
rollupOptions: {
output: {
/**
* @name Chunking strategy
* @description 1. Ensure these package names exist to avoid build errors
* @description 2. Remove this config if you don't need custom chunk splitting
*/
manualChunks: {
vue: ['vue', 'vue-router', 'pinia'],
element: ['element-plus', '@element-plus/icons-vue'],
vxe: ['vxe-table']
},
entryFileNames: 'assets/[name]-[hash].js',
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: `assets/[name]-[hash][extname]`
}
},
// Disable gzip size reporting for slightly better build performance
reportCompressedSize: false,
// Warn when chunk size exceeds 2048KB
chunkSizeWarningLimit: 2048
},
// ESBuild configuration
esbuild:
mode === 'development'
? undefined
: {
// Remove console.log in production
pure: ['console.log'],
// Remove debugger in production
drop: ['debugger'],
// Remove all comments in production
legalComments: 'none'
},
// Dependency optimization
optimizeDeps: {
include: ['element-plus/es/components/*/style/css']
},
// CSS configuration
css: {
// Run CSS preprocessor in worker thread
preprocessorMaxWorkers: true
},
// Plugin configuration
plugins: [
vue(),
// Import SVG files as Vue components
svgLoader({
defaultImport: 'url',
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// @see https://github.com/svg/svgo/issues/1128
removeViewBox: false
}
}
}
]
}
}),
// Auto-generate SvgIcon component and SVG sprites
SvgComponent({
iconDir: [resolve(__dirname, 'src/common/assets/icons')],
preserveColor: resolve(__dirname, 'src/common/assets/icons/preserve-color'),
dts: true,
dtsDir: resolve(__dirname, 'types/auto')
}),
// Atomic CSS
UnoCSS(),
// Auto-import APIs
AutoImport({
imports: ['vue', 'vue-router', 'pinia'],
dts: 'types/auto/auto-imports.d.ts',
resolvers: [ElementPlusResolver()]
}),
// Auto-import components
Components({
dts: 'types/auto/components.d.ts',
resolvers: [ElementPlusResolver()]
})
],
// Configuring Vitest: https://vitest.dev/config
test: {
include: ['tests/**/*.test.{ts,js}'],
environment: 'happy-dom',
server: {
deps: {
inline: ['element-plus']
}
}
}
};
});