-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathvite.config.ts
More file actions
56 lines (54 loc) · 1.64 KB
/
Copy pathvite.config.ts
File metadata and controls
56 lines (54 loc) · 1.64 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
import { fileURLToPath } from 'url'
import pkg from './package.json'
import dayjs from 'dayjs'
import { defineConfig, ConfigEnv, loadEnv } from 'vite'
import { wrapperEnv } from './build/utils'
import { createVitePlugins } from './build/vite/plugin'
import { createProxy } from './build/vite/proxy'
import { createBuild } from './build/vite/build'
const { dependencies, devDependencies, name, version } = pkg
// 应用信息
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
}
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }: ConfigEnv) => {
// console.log('command', command)
const root = process.cwd() // 当前工作目录
const isBuild = command === 'build' // 是否是构建 serve
const env = loadEnv(mode, root) // 加载env环境
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
const viteEnv = wrapperEnv(env)
// console.log('viteEnv', viteEnv)
const { VITE_PUBLIC_PATH, VITE_OUTPUT_DIR } = viteEnv
return {
base: VITE_PUBLIC_PATH,
root,
plugins: createVitePlugins(viteEnv, isBuild),
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
charset: false, // 避免出现: build时的 @charset 必须在第一行的警告
additionalData: `
@import "@/styles/mixin.scss";
@import "@/styles/variables.scss";
`
}
}
},
server: {
host: true,
proxy: createProxy()
},
build: createBuild(viteEnv),
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__)
}
}
})