-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
89 lines (87 loc) · 2.65 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
83
84
85
86
87
88
89
import { ConfigEnv, loadEnv, UserConfig } from "vite";
import { resolve } from "path";
import { VITE_DROP_CONSOLE, VITE_BASE_PATH } from "./config/constant";
import { createVitePlugins } from "./config/plugins";
import proxy from "./config/proxy";
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
const isBuild = command === "build";
const root = process.cwd();
const env = loadEnv(mode, root);
const { VITE_PORT, VITE_HTTP_API } = env;
return {
root: root,
publicDir: "public",
plugins: createVitePlugins(mode, isBuild),
base: VITE_BASE_PATH,
css: {
modules: {
generateScopedName: "[name]__[local]___[hash:base64:5]",
hashPrefix: "prefix",
},
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
resolve: {
alias: {
"@": `${resolve(__dirname, "src")}`,
config: `${resolve(__dirname, "config")}`,
},
// // 解析package.json中的字段
// mainFields: ["module", "jsnext:main", "jsnext", "browser"],
// 导入时想要省略的扩展名列表
extensions: [".less", ".js", ".ts", ".jsx", ".tsx", ".json"],
},
json: {
// 是否支持从 .json 文件中进行按名导入
namedExports: true,
// 若设置为 true,导入的 JSON 会被转换为 export default JSON.parse("...") 会比转译成对象字面量性能更好, 尤其是当 JSON 文件较大的时候。开启此项,则会禁用按名导入
stringify: false,
},
// 设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息
clearScreen: false,
// 调整控制台输出的级别 'info' | 'warn' | 'error' | 'silent'
logLevel: "info",
server: {
open: true,
host: "0.0.0.0",
port: parseInt(VITE_PORT),
proxy: proxy(VITE_HTTP_API),
},
esbuild: {
drop: VITE_DROP_CONSOLE ? ["console", "debugger"] : [],
// pure: VITE_DROP_CONSOLE ? ["console","debugger"] : [],
},
build: {
target: "modules",
outDir: "build",
assetsDir: "assets",
cssCodeSplit: true,
assetsInlineLimit: 4096,
sourcemap: false,
minify: "esbuild",
chunkSizeWarningLimit: 500,
emptyOutDir: true,
manifest: false,
rollupOptions: {
output: {
manualChunks: {
react: ["react"],
antd: ["antd"],
},
},
},
},
// 全局变量替换 Record<string, string>
define: {
_GLOBAL_VARS_: JSON.stringify({
...env,
MODE: mode,
BUILD_TIME: new Date().toLocaleString(),
}),
},
};
};