-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
76 lines (76 loc) · 2.31 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
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
base: "/", // 设置打包路径
plugins: [vue()], // 引入插件
resolve: { // 配置别名
alias: {
"@": path.resolve(__dirname, "./src"), // 设置 `@` 指向 `src` 目录
'element-plus$': 'element-plus/lib/index.esm.js', // 9月更新
},
},
css: {
preprocessorOptions: { // 引入全局less
less: {
additionalData: `
@import '@/assets/styles/variables.less';
@import '@/assets/styles/mixins.less';
@import '@/assets/styles/responsive.less';
`,
},
},
},
build: {
outDir: "dist", //指定输出路径
assetsDir: "assets", //指定静态资源存放路径
sourcemap: false, //是否构建source map 文件
minify: "terser", // 混淆器,terser 构建后文件体积更小,'terser' | 'esbuild'
chunkSizeWarningLimit: 1500, //chunk 大小警告的限制,默认500KB
rollupOptions: {
output: {
// 最小化拆分包
manualChunks(id) {
if (id.includes("node_modules")) {
return id
.toString()
.split("node_modules/")[1]
.split("/")[0]
.toString();
}
},
chunkFileNames: "js/[name].[hash].js", // 用于命名代码拆分时创建的共享块的输出命名,[name]表示文件名,[hash]表示该文件内容hash值
},
},
terserOptions: {
compress: {
drop_console: true, // 去掉console
drop_debugger: true, // 去掉debugger
},
output: {
comments: true, // 去掉注释内容
},
},
},
server: {
https: false, // 是否开启 https
open: false, // 是否自动在浏览器打开
cors: true, // 允许跨域 8月更新
port: 8080, // 端口号
host: "0.0.0.0",
proxy: {
"/api": {
target: "", // 后台接口
changeOrigin: true,
secure: false, // 如果是https接口,需要配置这个参数
ws: true, //websocket支持
rewrite: (path) => path.replace(/^\/api/, ""), // 重写接口
},
},
},
// 引入第三方的配置
optimizeDeps: {
include: [], // 引入第三方的配置
},
});