vite.config.js 2.0 KB

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