-
Notifications
You must be signed in to change notification settings - Fork 318
/
vite.config.ts
executable file
·63 lines (62 loc) · 1.85 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
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import dayjs from 'dayjs'
import { defineConfig, loadEnv } from 'vite'
import pkg from './package.json'
import createVitePlugins from './vite/plugins'
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd())
// 全局 scss 资源
const scssResources: string[] = []
fs.readdirSync('src/assets/styles/resources').forEach((dirname) => {
if (fs.statSync(`src/assets/styles/resources/${dirname}`).isFile()) {
scssResources.push(`@use "/src/assets/styles/resources/${dirname}" as *;`)
}
})
return {
// 开发服务器选项 https://cn.vitejs.dev/config/server-options
server: {
open: true,
port: 9000,
proxy: {
'/proxy': {
target: env.VITE_APP_API_BASEURL,
changeOrigin: command === 'serve' && env.VITE_OPEN_PROXY === 'true',
rewrite: path => path.replace(/\/proxy/, ''),
},
},
},
// 构建选项 https://cn.vitejs.dev/config/build-options
build: {
outDir: mode === 'production' ? 'dist' : `dist-${mode}`,
sourcemap: env.VITE_BUILD_SOURCEMAP === 'true',
},
define: {
__SYSTEM_INFO__: JSON.stringify({
pkg: {
version: pkg.version,
dependencies: pkg.dependencies,
devDependencies: pkg.devDependencies,
},
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}),
},
plugins: createVitePlugins(mode, command === 'build'),
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'#': path.resolve(__dirname, 'src/types'),
},
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
additionalData: scssResources.join(''),
},
},
},
}
})