vite.config.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { defineConfig, loadEnv } from "vite";
  2. import path from "path";
  3. import createVitePlugins from "./vite/plugins";
  4. import tailwindcss from "tailwindcss";
  5. import autoprefixer from "autoprefixer";
  6. import { monacoAlias } from "@qomo-platform/vite-plugin"
  7. const { networkInterfaces } = require("os");
  8. /** 获取本地IP地址 */
  9. function getLocalIpAddress() {
  10. const interfaces = networkInterfaces();
  11. for (const interfaceName of Object.keys(interfaces)) {
  12. for (const interfaceInfo of interfaces[interfaceName]) {
  13. if (!interfaceInfo.internal && interfaceInfo.family === "IPv4") {
  14. return interfaceInfo.address;
  15. }
  16. }
  17. }
  18. return "localhost"; // 如果没有找到非内部的 IPv4 地址,则返回 localhost
  19. }
  20. // https://vitejs.dev/config/
  21. export default defineConfig(({ mode, command }) => {
  22. const env = loadEnv(mode, process.cwd());
  23. const { VITE_APP_ENV ,VITE_APP_PATH} = env;
  24. return {
  25. // 部署生产环境和开发环境下的URL。
  26. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  27. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  28. base: VITE_APP_ENV === "production" ? `${VITE_APP_PATH}/` : "/",
  29. plugins: createVitePlugins(env, command === "build"),
  30. resolve: {
  31. // https://cn.vitejs.dev/config/#resolve-alias
  32. alias: {
  33. // 设置路径
  34. "~": path.resolve(__dirname, "./"),
  35. // 设置别名
  36. "@": path.resolve(__dirname, "./src"),
  37. ...monacoAlias
  38. },
  39. // https://cn.vitejs.dev/config/#resolve-extensions
  40. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  41. // 配置跨域请求头,解决开发环境的跨域问题
  42. },
  43. // vite 相关配置
  44. server: {
  45. port: 8082,
  46. // 关闭主机检查,使微应用可以被 fetch
  47. disableHostCheck: true,
  48. host: getLocalIpAddress(),
  49. open: true,
  50. hmr:{overlay:false},
  51. proxy: {
  52. // https://cn.vitejs.dev/config/#server-proxy
  53. "/qomo": {
  54. // target: "http://172.16.0.241:8095", //wq
  55. target: "http://172.16.0.214:8095", //bgy
  56. // target: "http://192.168.50.9:8095",
  57. changeOrigin: true,
  58. pathRewrite: {
  59. "^/qomo": "/qomo"
  60. }
  61. },
  62. },
  63. headers: {
  64. "Access-Control-Allow-Origin": "*"
  65. }
  66. },
  67. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  68. css: {
  69. postcss: {
  70. plugins: [
  71. tailwindcss,
  72. autoprefixer,
  73. {
  74. postcssPlugin: "internal:charset-removal",
  75. AtRule: {
  76. charset: atRule => {
  77. if (atRule.name === "charset") {
  78. atRule.remove();
  79. }
  80. }
  81. }
  82. },
  83. require("postcss-pxtorem")({
  84. rootValue: 144, // 根字体大小
  85. unitPrecision: 5,
  86. propList: ["*"],
  87. selectorBlackList: [],
  88. replace: true,
  89. mediaQuery: false
  90. //exclude: /node_modules/i
  91. }),
  92. ]
  93. }
  94. }
  95. };
  96. });