-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathvite.config.ts
76 lines (73 loc) · 1.92 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 { ConfigEnv, loadEnv, UserConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import legacy from "@vitejs/plugin-legacy";
import { resolve } from "path";
import styleImport from "vite-plugin-style-import"; // 按需导入ui组件
const CWD = process.cwd(); // 项目根目录
export default ({ mode }: ConfigEnv): UserConfig => {
const { VITE_BASE_URL } = loadEnv(mode, CWD); // mode环境变量
return {
base: VITE_BASE_URL,
css: {
modules: {
localsConvention: "camelCase", // 默认只支持驼峰,修改为同时支持横线和驼峰
},
preprocessorOptions: {
scss: {
additionalData: '@import "./src/styles/index.scss";',
},
},
},
plugins: [
vue(),
vueJsx(),
legacy({
targets: ["defaults", "not IE 11"],
}),
styleImport({
// 手动导入组件
libs: [
{
libraryName: "vant",
esModule: true,
resolveStyle: (name) => {
return `vant/es/${name}/style`;
},
},
],
}),
],
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
build: {
target: "modules",
polyfillModulePreload: true,
outDir: "dist",
assetsDir: "static",
minify: "terser", // 混淆器
},
optimizeDeps: {
include: ["vue", "vue-router", "vant"],
exclude: ["vue-demi"],
},
server: {
host: "0.0.0.0",
port: 8089, // 设置服务启动端口号
open: true,
cors: true, // 允许跨域
// 设置代理,根据项目实际情况配置
proxy: {
"/client_api": {
target: "http://localhost:3000/client_api/",
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/client_api/, "/"),
},
},
},
};
};