-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
82 lines (78 loc) · 2.18 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
import path from "path";
import { fileURLToPath, URL } from "url";
import type { UserConfigExport, ConfigEnv } from "vite";
import Vue from "@vitejs/plugin-vue";
import VueJSX from "@vitejs/plugin-vue-jsx";
// import { createStyleImportPlugin, AndDesignVueResolve } from "vite-plugin-style-import";
import VueI18n from "@intlify/vite-plugin-vue-i18n";
import { viteMockServe } from "vite-plugin-mock";
import UnoCSS from "unocss/vite";
// import Components from "unplugin-vue-components/vite";
// import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default ({ command }: ConfigEnv): UserConfigExport => {
const isBuild = command === "build";
return {
// 1. 如果使用的是ant-design 系列的 需要配置这个
// 2. 确保less安装在依赖 `yarn add less -D`
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true
}
}
},
plugins: [
Vue(),
VueJSX(),
UnoCSS(),
viteMockServe({
ignore: /^_/, // 忽略自动读取以_开头的文件
mockPath: "mock",
logger: true,
localEnabled: !isBuild,
prodEnabled: isBuild,
injectCode: `
import { setupProdMockServer } from '../mock/_mockProdServer';
setupProdMockServer();
`
}),
// createStyleImportPlugin({
// resolves: [AndDesignVueResolve()]
// }),
VueI18n({
// if you want to use Vue I18n Legacy API, you need to set `compositionOnly: false`
// compositionOnly: false,
// you need to set i18n resource including paths !
// fix:https://github.com/intlify/vue-i18n-next/issues/789
include: path.resolve(__dirname, "/src/locales/lang/json/**")
})
// Components({
// resolvers: [AntDesignVueResolver()]
// })
],
server: {
host: "0.0.0.0",
port: 8888,
open: true,
proxy: {
"/api": {
// 真实地址
target: "xxxxx",
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, "")
},
"/mock-api": {
target: "http://localhost:8888",
changeOrigin: true,
rewrite: path => path.replace(/^\/mock-api/, "")
}
}
},
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url))
}
}
};
};