vite.config.js 3.2KB

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