-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.ts
145 lines (130 loc) · 3.44 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import path, { resolve } from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import tsconfigPaths from "vite-tsconfig-paths";
import copy from "rollup-plugin-copy";
import pkg from "./package.json";
import moment from "moment";
const { dependencies, devDependencies, name, version } = pkg;
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: moment().format("YYYY-MM-DD HH:mm:ss"),
};
// https://vitejs.dev/config/
export default defineConfig({
base: "./",
define: {
// setting vue-i18-next
// Suppress warning
__APP_INFO__: JSON.stringify(__APP_INFO__),
},
// 配置别名
resolve: {
alias: [
{
find: /^~/,
replacement: "",
},
{
find: "@",
replacement: resolve(__dirname, "src"),
},
{
find: "@API",
replacement: resolve(__dirname, "src/api"),
},
{
find: "@ASS",
replacement: resolve(__dirname, "src/assets"),
},
{
find: "@COM",
replacement: resolve(__dirname, "src/components"),
},
{
find: "@VIE",
replacement: resolve(__dirname, "src/views"),
},
],
},
plugins: [
vue(),
tsconfigPaths(),
// When compiling the project, copy the static file into the dist directory
copy({
targets: [{ src: "static/*", dest: "dist/static" }],
hook: "writeBundle", // notice here
}),
],
css: {
preprocessorOptions: {
less: {
modifyVars: {
hack: `true; @import "@ASS/css/theme.less";`,
},
},
},
},
// 构建
build: {
// 传递给 Terser 的更多 minify 选项。
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
// 自定义底层的 Rollup 打包配置
rollupOptions: {
output: {
manualChunks: {},
},
},
// chunk 大小警告的限制
chunkSizeWarningLimit: 800, // FIXME: 鸵鸟 = =...
// 浏览器兼容性 "esnext"|"modules"
target: "modules",
// 输出路径
outDir: "dist",
// 生成静态资源的存放路径
assetsDir: "assets",
// 小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求。设置为 0 可以完全禁用此项
assetsInlineLimit: 4096,
// 启用/禁用 CSS 代码拆分
cssCodeSplit: true,
// 构建后是否生成 source map 文件
sourcemap: false,
// @rollup/plugin-commonjs 插件的选项
commonjsOptions: {},
// 构建的库
//当设置为 true,构建后将会生成 manifest.json 文件
manifest: false,
// 设置为 false 可以禁用最小化混淆,
// 或是用来指定使用哪种混淆器
// boolean | 'terser' | 'esbuild'
minify: "terser",
// 设置为 false 来禁用将构建后的文件写入磁盘
write: true,
// 默认情况下,若 outDir 在 root 目录下,则 Vite 会在构建时清空该目录。
emptyOutDir: true,
// 启用/禁用 brotli 压缩大小报告
brotliSize: true,
},
server: {
open: true,
port: 6060,
// Load proxy configuration from .env
// proxy: createProxy(VITE_PROXY),
proxy: {
"/api": {
target: "https://xxx.xx.xx/xxx",
changeOrigin: true,
ws: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
hmr: {
overlay: true,
},
},
});