2021-10-16 16:16:58 +08:00
|
|
|
|
import { resolve } from "path";
|
2021-12-06 17:11:15 +08:00
|
|
|
|
import { warpperEnv, regExps } from "./build";
|
2022-02-05 14:45:20 +08:00
|
|
|
|
import { getPluginsList } from "./build/plugins";
|
2021-12-06 17:11:15 +08:00
|
|
|
|
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
|
2021-10-16 16:16:58 +08:00
|
|
|
|
|
2021-12-06 17:11:15 +08:00
|
|
|
|
// 当前执行node命令时文件夹的地址(工作目录)
|
|
|
|
|
const root: string = process.cwd();
|
|
|
|
|
|
|
|
|
|
// 路径查找
|
2021-10-19 20:37:36 +08:00
|
|
|
|
const pathResolve = (dir: string): string => {
|
2021-10-16 16:16:58 +08:00
|
|
|
|
return resolve(__dirname, ".", dir);
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-06 17:11:15 +08:00
|
|
|
|
// 设置别名
|
2021-10-16 16:16:58 +08:00
|
|
|
|
const alias: Record<string, string> = {
|
|
|
|
|
"/@": pathResolve("src"),
|
|
|
|
|
"@build": pathResolve("build"),
|
2021-12-06 17:11:15 +08:00
|
|
|
|
//解决开发环境下的警告
|
2021-10-16 16:16:58 +08:00
|
|
|
|
"vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
|
2021-12-06 17:11:15 +08:00
|
|
|
|
const {
|
|
|
|
|
VITE_PORT,
|
2021-12-17 15:09:02 +08:00
|
|
|
|
VITE_LEGACY,
|
2021-12-06 17:11:15 +08:00
|
|
|
|
VITE_PUBLIC_PATH,
|
|
|
|
|
VITE_PROXY_DOMAIN,
|
|
|
|
|
VITE_PROXY_DOMAIN_REAL
|
|
|
|
|
} = warpperEnv(loadEnv(mode, root));
|
2021-10-16 16:16:58 +08:00
|
|
|
|
return {
|
2021-12-06 17:11:15 +08:00
|
|
|
|
base: VITE_PUBLIC_PATH,
|
2021-10-16 16:16:58 +08:00
|
|
|
|
root,
|
|
|
|
|
resolve: {
|
|
|
|
|
alias
|
|
|
|
|
},
|
2021-12-08 14:32:36 +08:00
|
|
|
|
css: {
|
|
|
|
|
// https://github.com/vitejs/vite/issues/5833
|
|
|
|
|
postcss: {
|
|
|
|
|
plugins: [
|
|
|
|
|
{
|
|
|
|
|
postcssPlugin: "internal:charset-removal",
|
|
|
|
|
AtRule: {
|
|
|
|
|
charset: atRule => {
|
|
|
|
|
if (atRule.name === "charset") {
|
|
|
|
|
atRule.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-10-16 16:16:58 +08:00
|
|
|
|
// 服务端渲染
|
|
|
|
|
server: {
|
|
|
|
|
// 是否开启 https
|
|
|
|
|
https: false,
|
2021-12-06 17:11:15 +08:00
|
|
|
|
// 端口号
|
2021-10-16 16:16:58 +08:00
|
|
|
|
port: VITE_PORT,
|
|
|
|
|
host: "0.0.0.0",
|
|
|
|
|
// 本地跨域代理
|
2021-12-06 17:11:15 +08:00
|
|
|
|
proxy:
|
|
|
|
|
VITE_PROXY_DOMAIN_REAL.length > 0
|
|
|
|
|
? {
|
|
|
|
|
[VITE_PROXY_DOMAIN]: {
|
|
|
|
|
target: VITE_PROXY_DOMAIN_REAL,
|
|
|
|
|
// ws: true,
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
rewrite: (path: string) => regExps(path, VITE_PROXY_DOMAIN)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
: null
|
2021-10-16 16:16:58 +08:00
|
|
|
|
},
|
2022-02-05 14:45:20 +08:00
|
|
|
|
plugins: getPluginsList(command, VITE_LEGACY),
|
2021-10-16 16:16:58 +08:00
|
|
|
|
optimizeDeps: {
|
|
|
|
|
include: [
|
2022-01-20 00:00:25 +08:00
|
|
|
|
"pinia",
|
|
|
|
|
"vue-i18n",
|
|
|
|
|
"lodash-es",
|
|
|
|
|
"@vueuse/core",
|
2022-02-05 14:45:20 +08:00
|
|
|
|
"@iconify/vue",
|
|
|
|
|
"element-plus/lib/locale/lang/en",
|
|
|
|
|
"element-plus/lib/locale/lang/zh-cn"
|
2021-11-10 22:12:47 +08:00
|
|
|
|
],
|
|
|
|
|
exclude: ["@zougt/vite-plugin-theme-preprocessor/dist/browser-utils"]
|
2021-10-16 16:16:58 +08:00
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
sourcemap: false,
|
|
|
|
|
brotliSize: false,
|
|
|
|
|
// 消除打包大小超过500kb警告
|
2021-12-08 14:32:36 +08:00
|
|
|
|
chunkSizeWarningLimit: 2000
|
2021-10-16 16:16:58 +08:00
|
|
|
|
},
|
|
|
|
|
define: {
|
|
|
|
|
__INTLIFY_PROD_DEVTOOLS__: false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|