forked from seraph1cal/ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
82 lines (80 loc) · 2.41 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite';
import { resolve } from 'path';
import { wrapperEnv } from './build/getEnv';
import { createProxy } from './build/proxy';
import { createVitePlugins } from './build/plugins';
import unocss from 'unocss/vite';
import pkg from './package.json';
import dayjs from 'dayjs';
const { dependencies, devDependencies, name, version } = pkg;
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
};
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
console.log('root---process.cwd()', root);
const env = loadEnv(mode, root);
console.log('env------', env);
const viteEnv = wrapperEnv(env);
return {
base: viteEnv.VITE_PUBLIC_PATH,
root,
resolve: {
alias: {
'@': resolve(__dirname, './src'),
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
}
},
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__)
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "@/styles/var.scss";`
}
}
},
server: {
host: '0.0.0.0',
port: viteEnv.VITE_PORT,
open: viteEnv.VITE_OPEN,
cors: true,
// Load proxy configuration from .env.development
proxy: createProxy(viteEnv.VITE_PROXY)
},
preview: {
port: 5000
},
plugins: [createVitePlugins(viteEnv), unocss()],
esbuild: {
pure: viteEnv.VITE_DROP_CONSOLE ? ['console.log', 'debugger'] : []
},
build: {
outDir: 'dist',
minify: 'esbuild',
// esbuild 打包更快,但是不能去除 console.log,terser打包慢,但能去除 console.log
// minify: "terser",
// terserOptions: {
// compress: {
// drop_console: viteEnv.VITE_DROP_CONSOLE,
// drop_debugger: true
// }
// },
sourcemap: false,
// 禁用 gzip 压缩大小报告,可略微减少打包时间
reportCompressedSize: false,
// 规定触发警告的 chunk 大小
chunkSizeWarningLimit: 2000,
rollupOptions: {
output: {
// Static resource classification and packaging
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]'
}
}
}
};
});