1
- import { defineConfig } from 'vite'
1
+ import { defineConfig , loadEnv } from 'vite'
2
2
import vue from '@vitejs/plugin-vue'
3
3
import vueJsx from '@vitejs/plugin-vue-jsx'
4
4
import { visualizer } from 'rollup-plugin-visualizer'
@@ -15,76 +15,80 @@ import postcssPresetEnv from 'postcss-preset-env'
15
15
import { formatDate } from './src/utils/time'
16
16
17
17
// https://vitejs.dev/config/
18
- export default defineConfig ( {
19
- base : '/' ,
20
- resolve : {
21
- alias : {
22
- '@' : resolve ( __dirname , 'src' ) ,
18
+ export default ( { mode } ) => {
19
+ const env = loadEnv ( mode , process . cwd ( ) )
20
+ const { VITE_APP_BASE_URL : BASE_URL = '/' } = env
21
+ return defineConfig ( {
22
+ base : BASE_URL ,
23
+ resolve : {
24
+ alias : {
25
+ '@' : resolve ( __dirname , 'src' ) ,
26
+ } ,
23
27
} ,
24
- } ,
25
- build : {
26
- terserOptions : {
27
- compress : {
28
- keep_infinity : true , // 防止 Infinity 被压缩成 1/0,这可能会导致 Chrome 上的性能问题
29
- drop_console : true , // 生产环境去除 console
30
- drop_debugger : true , // 生产环境去除 debugger
28
+ build : {
29
+ terserOptions : {
30
+ compress : {
31
+ keep_infinity : true , // 防止 Infinity 被压缩成 1/0,这可能会导致 Chrome 上的性能问题
32
+ drop_console : true , // 生产环境去除 console
33
+ drop_debugger : true , // 生产环境去除 debugger
34
+ } ,
31
35
} ,
32
36
} ,
33
- } ,
34
- css : {
35
- preprocessorOptions : {
36
- scss : {
37
- additionalData : `@use "@/styles/theme.scss" as *;` ,
37
+ css : {
38
+ preprocessorOptions : {
39
+ scss : {
40
+ additionalData : `@use "@/styles/theme.scss" as *;` ,
41
+ } ,
42
+ } ,
43
+ postcss : {
44
+ plugins : [ postcssPresetEnv ( ) ] ,
38
45
} ,
39
46
} ,
40
- postcss : {
41
- plugins : [ postcssPresetEnv ( ) ] ,
47
+ define : {
48
+ __PKG_TIME__ : JSON . stringify ( formatDate ( new Date ( ) ) ) ,
42
49
} ,
43
- } ,
44
- define : {
45
- __PKG_TIME__ : JSON . stringify ( formatDate ( new Date ( ) ) ) ,
46
- } ,
47
- plugins : [
48
- vue ( ) ,
49
- vueJsx ( ) ,
50
- visualizer ( {
51
- // open: true, //注意这里要设置为true,否则无效
52
- gzipSize : true ,
53
- brotliSize : true ,
54
- } ) ,
55
- AutoImport ( {
56
- imports : [ 'vue' , 'vue-router' , 'pinia' , '@vueuse/core' ] ,
57
- dts : './src/auto-imports.d.ts' ,
58
- eslintrc : {
59
- enabled : false , // Default `false`
60
- filepath : './.eslintrc-auto-import.json' , // Default `./.eslintrc-auto-import.json`
61
- globalsPropValue : true , // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
62
- } ,
63
- resolvers : [ ElementPlusResolver ( ) ] ,
64
- } ) ,
65
- Components ( {
66
- dirs : [ 'src/components' ] ,
67
- resolvers : [ ElementPlusResolver ( ) ] ,
68
- dts : 'src/components.d.ts' ,
69
- include : [ / \. v u e $ / , / \. v u e \? v u e / , / \. t s x $ / , / \. m d $ / ] ,
70
- } ) ,
71
- // ElementPlus(),
72
- Unocss ( ) ,
73
- viteMockServe ( {
74
- supportTs : false ,
75
- logger : false ,
76
- mockPath : './src/mock' ,
77
- localEnabled : true , // 开发打包开关
78
- prodEnabled : true , // 生产打包开关 // 这样可以控制关闭mock的时候不让mock打包到最终代码内
79
- injectCode : ` import { setupProdMockServer } from './mockProdServer'; setupProdMockServer(); ` ,
80
- } ) ,
81
- vueSetupExtend ( ) ,
82
- eslintPlugin ( ) ,
83
- webUpdateNotice ( { logVersion : true , injectFileBase : '/' } ) ,
84
- ] ,
85
- server : {
86
- host : '0.0.0.0' ,
87
- open : true ,
88
- port : 4646 ,
89
- } ,
90
- } )
50
+ plugins : [
51
+ vue ( ) ,
52
+ vueJsx ( ) ,
53
+ visualizer ( {
54
+ // open: true, //注意这里要设置为true,否则无效
55
+ gzipSize : true ,
56
+ brotliSize : true ,
57
+ } ) ,
58
+ AutoImport ( {
59
+ imports : [ 'vue' , 'vue-router' , 'pinia' , '@vueuse/core' ] ,
60
+ dts : './src/auto-imports.d.ts' ,
61
+ eslintrc : {
62
+ enabled : false , // Default `false`
63
+ filepath : './.eslintrc-auto-import.json' , // Default `./.eslintrc-auto-import.json`
64
+ globalsPropValue : true , // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
65
+ } ,
66
+ resolvers : [ ElementPlusResolver ( ) ] ,
67
+ } ) ,
68
+ Components ( {
69
+ dirs : [ 'src/components' ] ,
70
+ resolvers : [ ElementPlusResolver ( ) ] ,
71
+ dts : 'src/components.d.ts' ,
72
+ include : [ / \. v u e $ / , / \. v u e \? v u e / , / \. t s x $ / , / \. m d $ / ] ,
73
+ } ) ,
74
+ // ElementPlus(),
75
+ Unocss ( ) ,
76
+ viteMockServe ( {
77
+ supportTs : false ,
78
+ logger : false ,
79
+ mockPath : './src/mock' ,
80
+ localEnabled : true , // 开发打包开关
81
+ prodEnabled : true , // 生产打包开关 // 这样可以控制关闭mock的时候不让mock打包到最终代码内
82
+ injectCode : ` import { setupProdMockServer } from './mockProdServer'; setupProdMockServer(); ` ,
83
+ } ) ,
84
+ vueSetupExtend ( ) ,
85
+ eslintPlugin ( ) ,
86
+ webUpdateNotice ( { logVersion : true , injectFileBase : BASE_URL } ) ,
87
+ ] ,
88
+ server : {
89
+ host : '0.0.0.0' ,
90
+ open : true ,
91
+ port : 4646 ,
92
+ } ,
93
+ } )
94
+ }
0 commit comments