vite.config.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { defineConfig, loadEnv } from "vite";
  2. import path from "path";
  3. import createVitePlugins from "./vite/plugins";
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode, command }) => {
  6. const env = loadEnv(mode, process.cwd());
  7. const { VITE_APP_ENV } = env;
  8. return {
  9. // 部署生产环境和开发环境下的URL。
  10. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  11. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  12. base: VITE_APP_ENV === "production" ? "/" : "/",
  13. plugins: createVitePlugins(env, command === "build"),
  14. resolve: {
  15. // https://cn.vitejs.dev/config/#resolve-alias
  16. alias: {
  17. // 设置路径
  18. "~": path.resolve(__dirname, "./"),
  19. // 设置别名
  20. "@": path.resolve(__dirname, "./src"),
  21. },
  22. // https://cn.vitejs.dev/config/#resolve-extensions
  23. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  24. },
  25. // vite 相关配置
  26. server: {
  27. port: 80,
  28. host: true,
  29. open: true,
  30. proxy: {
  31. // https://cn.vitejs.dev/config/#server-proxy
  32. "/dev-api": {
  33. target: "http://172.16.8.42:8080",
  34. changeOrigin: true,
  35. rewrite: (p) => p.replace(/^\/dev-api/, ""),
  36. },
  37. },
  38. },
  39. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  40. css: {
  41. postcss: {
  42. plugins: [
  43. {
  44. postcssPlugin: "internal:charset-removal",
  45. AtRule: {
  46. charset: (atRule) => {
  47. if (atRule.name === "charset") {
  48. atRule.remove();
  49. }
  50. },
  51. },
  52. },
  53. ],
  54. },
  55. },
  56. };
  57. });