-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
88 lines (84 loc) · 2.56 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
// @ts-ignore
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite'
// @ts-ignore
import setupPlugins from './vite'
// @ts-ignore
import { resolve } from 'path'
// @ts-ignore
import { wrapperEnv } from './src/utils/getEnvConfig'
// @ts-ignore
import pkg from "./package.json";
// @ts-ignore
import dayjs from "dayjs";
const { dependencies, devDependencies, name, version } = pkg;
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss")
};
/** 路径查找 */
const pathResolve = (dir: string): string => {
return resolve(__dirname, ".", dir);
};
/** 设置别名 */
const alias: Record<string, string> | Array<{ find: string | RegExp, replacement: string }> = {
"@": pathResolve("src"),
"img": pathResolve("./src/assets/image/"),
"com": pathResolve("./src/components/"),
"api": pathResolve("./src/apis/"),
"s": pathResolve("./src/styles/"),
"u": pathResolve("./src/utils/"),
"v": pathResolve("./src/views/"),
"types": pathResolve("./src/types/"),
"vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
};
export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => {
const isBuild = command === 'build' ? true : false
const env = loadEnv(mode, process.cwd());
const viteEnv = wrapperEnv(env);
return {
base: viteEnv.VITE_PUBLIC_PATH,
plugins: setupPlugins(viteEnv, isBuild),//挂载插件
resolve: {
alias,
},
server: {
host: '0.0.0.0',
port: viteEnv.VITE_PORT,
open: viteEnv.VITE_DEV_OPEN,
cors: true,
// 跨域代理配置
proxy: {
// "/api": {
// target: "https://www.fastmock.site/mock/c5fc1ef03a33b327e9ed7f5130bc17ca/WAdmin", // fastmock
// changeOrigin: true,
// rewrite: path => path.replace(/^\/api/, "")
// }
}
},
build: {
outDir: "dist",
assetsDir: "assets", //指定静态资源存放路径
sourcemap: false, //是否构建source map 文件
terserOptions: viteEnv.VITE_DROP_CONSOLE ? {
// 生产环境移除console
compress: {
drop_console: true,
drop_debugger: true,
},
} : {},
},
define: {
__VUE_I18N_FULL_INSTALL__: true,
__VUE_I18N_LEGACY_API__: false,
__INTLIFY_PROD_DEVTOOLS__: false,
__APP_INFO__: JSON.stringify(__APP_INFO__)
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true
}
}
}
}
})