vite.config.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.162:8082", //bgy
  56. target: "http://172.16.2.127:8082", //bgy远程
  57. // target: "http://192.168.50.9:2999",//中智平台
  58. changeOrigin: true,
  59. pathRewrite: {
  60. "^/qomo": "/qomo"
  61. }
  62. },
  63. "/qomo/flowSocket": {
  64. // target: 'ws://192.168.0.66:60601/',这是后端接口地址
  65. target: 'ws://172.16.0.162:8082',
  66. // target: 'ws://192.168.50.99:2999',
  67. changeOrigin: true,
  68. ws: true
  69. },
  70. "/qomo/taskSocket": {
  71. // target: 'ws://192.168.0.66:60601/',这是后端接口地址
  72. target: 'ws://172.16.0.162:8082',
  73. // target: 'ws://192.168.50.99:2999',
  74. changeOrigin: true,
  75. ws: true
  76. },
  77. },
  78. headers: {
  79. "Access-Control-Allow-Origin": "*"
  80. }
  81. },
  82. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  83. css: {
  84. postcss: {
  85. plugins: [
  86. tailwindcss,
  87. autoprefixer,
  88. {
  89. postcssPlugin: "internal:charset-removal",
  90. AtRule: {
  91. charset: atRule => {
  92. if (atRule.name === "charset") {
  93. atRule.remove();
  94. }
  95. }
  96. }
  97. },
  98. require("postcss-pxtorem")({
  99. rootValue: 144, // 根字体大小
  100. unitPrecision: 5,
  101. propList: ["*"],
  102. selectorBlackList: [],
  103. replace: true,
  104. mediaQuery: false
  105. //exclude: /node_modules/i
  106. }),
  107. ]
  108. }
  109. }
  110. };
  111. });