vite.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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" ? "/admin" : "/",
  13. plugins: createVitePlugins(env, command === "build"),
  14. build: {
  15. outDir: 'admin'
  16. },
  17. resolve: {
  18. // https://cn.vitejs.dev/config/#resolve-alias
  19. alias: {
  20. // 设置路径
  21. "~": path.resolve(__dirname, "./"),
  22. // 设置别名
  23. "@": path.resolve(__dirname, "./src"),
  24. },
  25. // https://cn.vitejs.dev/config/#resolve-extensions
  26. extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
  27. },
  28. // vite 相关配置
  29. server: {
  30. port: 80,
  31. host: true,
  32. open: true,
  33. proxy: {
  34. // https://cn.vitejs.dev/config/#server-proxy
  35. "/dev-api": {
  36. target: "http://172.16.10.61:8080",
  37. // target: 'https://vue.ruoyi.vip/prod-api',
  38. changeOrigin: true,
  39. rewrite: (p) => p.replace(/^\/dev-api/, ""),
  40. },
  41. },
  42. },
  43. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  44. css: {
  45. postcss: {
  46. plugins: [
  47. {
  48. postcssPlugin: "internal:charset-removal",
  49. AtRule: {
  50. charset: (atRule) => {
  51. if (atRule.name === "charset") {
  52. atRule.remove();
  53. }
  54. },
  55. },
  56. },
  57. ],
  58. },
  59. },
  60. };
  61. });