-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
86 lines (84 loc) · 2.28 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
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:当得当前文件的绝对路径
"@": path.resolve(__dirname, "./src"),
},
},
// 自动导入 less 文件
css: {
preprocessorOptions: {
less: {
additionalData: `
@import '@/assets/styles/variables.less';
@import '@/assets/styles/mixins.less';
@import '@/assets/styles/responsive.less';
`,
},
},
},
build: {
outDir: "dist",
// 9月更新
assetsDir: "assets", //指定静态资源存放路径
sourcemap: false, //是否构建source map 文件
// 10月更新
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: {
// 生产环境移除console
compress: {
drop_console: true,
drop_debugger: true,
},
// 10月更新
output: {
comments: true, // 去掉注释内容
},
},
},
server: {
https: false, // 是否开启 https
open: false, // 是否自动在浏览器打开
cors: true, // 允许跨域 8月更新
port: 3000, // 端口号
host: "0.0.0.0",
proxy: {
"/api": {
target: "", // 后台接口
changeOrigin: true,
secure: false, // 如果是https接口,需要配置这个参数
// ws: true, //websocket支持
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
// 引入第三方的配置
optimizeDeps: {
include: [],
},
});