vite.config.js 2.1 KB

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