-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
60 lines (59 loc) · 1.66 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
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import type { ConfigEnv } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import Pages from 'vite-plugin-pages'
export default ({ command, mode }: ConfigEnv) => {
const currentEnv = loadEnv(mode, process.cwd())
console.log('当前模式', command)
console.log('当前环境配置', currentEnv) //loadEnv即加载根目录下.env.[mode]环境配置文件
return defineConfig({
plugins: [
vue(),
Pages({
exclude: ['**/components/*'],
}),
AutoImport({
imports: ['vue', 'vue-router', '@vueuse/core', 'pinia'],
dts: './src/auto-imports.d.ts',
dirs: ['src/store'],
// vueTemplate: true,
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
},
}),
],
//项目部署的基础路径,
base: currentEnv.VITE_PUBLIC_PATH,
mode: mode,
resolve: {
//别名
alias: {
'@': resolve(__dirname, './src'),
},
},
server: {
proxy: {
'/api': {
target: 'http://xxxxxx.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
css: {
// css预处理器
preprocessorOptions: {
sass: {},
},
},
//构建
build: {
outDir: mode === 'docker' ? 'dist' : 'docs',
// assetsDir: 'assets', //指定生成静态资源的存放路径(相对于 build.outDir)。
sourcemap: mode != 'production',
},
})
}