2025-05-21 23:13:05 +08:00
|
|
|
|
import { defineConfig, loadEnv } from "vite";
|
|
|
|
|
import path from "path";
|
|
|
|
|
import createVitePlugins from "./vite/plugins";
|
2024-08-17 12:11:19 +08:00
|
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
|
|
|
export default defineConfig(({ mode, command }) => {
|
2025-05-21 23:13:05 +08:00
|
|
|
|
const env = loadEnv(mode, process.cwd());
|
|
|
|
|
const { VITE_APP_ENV } = env;
|
2024-08-17 12:11:19 +08:00
|
|
|
|
return {
|
|
|
|
|
// 部署生产环境和开发环境下的URL。
|
|
|
|
|
// 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
|
|
|
|
|
// 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
|
2025-05-21 23:13:05 +08:00
|
|
|
|
base: VITE_APP_ENV === "production" ? "/xd/" : "/xd/",
|
|
|
|
|
plugins: createVitePlugins(env, command === "build"),
|
2024-08-17 12:11:19 +08:00
|
|
|
|
resolve: {
|
|
|
|
|
// https://cn.vitejs.dev/config/#resolve-alias
|
|
|
|
|
alias: {
|
|
|
|
|
// 设置路径
|
2025-05-21 23:13:05 +08:00
|
|
|
|
"~": path.resolve(__dirname, "./"),
|
2024-08-17 12:11:19 +08:00
|
|
|
|
// 设置别名
|
2025-05-21 23:13:05 +08:00
|
|
|
|
"@": path.resolve(__dirname, "./src"),
|
2024-08-17 12:11:19 +08:00
|
|
|
|
},
|
|
|
|
|
// https://cn.vitejs.dev/config/#resolve-extensions
|
2025-05-21 23:13:05 +08:00
|
|
|
|
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
|
2024-08-17 12:11:19 +08:00
|
|
|
|
},
|
|
|
|
|
// vite 相关配置
|
|
|
|
|
server: {
|
|
|
|
|
port: 80,
|
|
|
|
|
host: true,
|
|
|
|
|
open: true,
|
|
|
|
|
proxy: {
|
2025-01-06 23:33:36 +08:00
|
|
|
|
"/prod-api": {
|
2025-05-21 23:13:05 +08:00
|
|
|
|
//target: "http://localhost:8080",
|
|
|
|
|
target: "http://62.234.3.186",
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
pathRewrite: {
|
|
|
|
|
"^/prod-api": "/",
|
|
|
|
|
},
|
2025-01-06 23:33:36 +08:00
|
|
|
|
},
|
2024-08-17 12:11:19 +08:00
|
|
|
|
// https://cn.vitejs.dev/config/#server-proxy
|
2025-05-21 23:13:05 +08:00
|
|
|
|
"/dev-api": {
|
|
|
|
|
target: "http://localhost:8080",
|
2024-08-17 12:11:19 +08:00
|
|
|
|
changeOrigin: true,
|
2025-05-21 23:13:05 +08:00
|
|
|
|
rewrite: (p) => p.replace(/^\/dev-api/, ""),
|
2024-09-01 22:29:20 +08:00
|
|
|
|
},
|
2025-05-21 23:13:05 +08:00
|
|
|
|
"/statics": {
|
|
|
|
|
target:
|
|
|
|
|
VITE_APP_ENV === "production"
|
|
|
|
|
? "http://62.234.3.186"
|
|
|
|
|
: `http://localhost:9300`,
|
2025-01-08 00:24:03 +08:00
|
|
|
|
//target: 'http://62.234.3.186',
|
2024-09-01 22:29:20 +08:00
|
|
|
|
changeOrigin: true,
|
2025-01-07 00:34:41 +08:00
|
|
|
|
pathRewrite: {
|
|
|
|
|
"^/statics": "/",
|
|
|
|
|
},
|
2024-09-01 22:29:20 +08:00
|
|
|
|
},
|
2025-05-21 23:13:05 +08:00
|
|
|
|
},
|
2024-08-17 12:11:19 +08:00
|
|
|
|
},
|
|
|
|
|
//fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
|
|
|
|
|
css: {
|
|
|
|
|
postcss: {
|
|
|
|
|
plugins: [
|
|
|
|
|
{
|
2025-05-21 23:13:05 +08:00
|
|
|
|
postcssPlugin: "internal:charset-removal",
|
2024-08-17 12:11:19 +08:00
|
|
|
|
AtRule: {
|
|
|
|
|
charset: (atRule) => {
|
2025-05-21 23:13:05 +08:00
|
|
|
|
if (atRule.name === "charset") {
|
2024-08-17 12:11:19 +08:00
|
|
|
|
atRule.remove();
|
|
|
|
|
}
|
2025-05-21 23:13:05 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-08-20 22:48:49 +08:00
|
|
|
|
optimizeDeps: {
|
2025-05-21 23:13:05 +08:00
|
|
|
|
include: ["@/lib/vform/designer.umd.js"], //此处路径必须跟main.js中import路径完全一致!
|
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
outDir: "dist/xd/",
|
2024-10-15 23:22:33 +08:00
|
|
|
|
/* 其他build生产打包配置省略 */
|
|
|
|
|
//...
|
|
|
|
|
commonjsOptions: {
|
2025-05-21 23:13:05 +08:00
|
|
|
|
include: /node_modules|lib/, //这里记得把lib目录加进来,否则生产打包会报错!!
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
});
|