vite.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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: 88,
  36. host: true,
  37. open: true,
  38. proxy: {
  39. '/dev-api': {
  40. // target: 'http://192.168.4.24:8084',
  41. target: 'http://116.205.170.159:8085',
  42. // target: 'http://10.60.10.144:8085',
  43. // target: 'http://192.168.4.124:8084',
  44. changeOrigin: true,
  45. rewrite: (p) => p.replace(/^\/dev-api/, '')
  46. },
  47. // https://cn.vitejs.dev/config/#server-proxy
  48. '/dev-api/open_war': {
  49. target: 'http://116.205.170.159:8080/open_war',
  50. changeOrigin: true,
  51. rewrite: (p) => p.replace(/^\/dev-api\/open_war/, '')
  52. },
  53. '/dev-api/ocean-api': {
  54. target: 'https://www.enstation.com:8083',
  55. changeOrigin: true,
  56. rewrite: (p) => p.replace(/^\/dev-api\/ocean-api/, '')
  57. },
  58. '/dev-api/baidubce-api': {
  59. target: 'https://aip.baidubce.com',
  60. changeOrigin: true,
  61. rewrite: (p) => p.replace(/^\/dev-api\/baidubce-api/, '')
  62. },
  63. '/dev-api/baidu-chat': {
  64. target: 'https://aip.baidubce.com',
  65. changeOrigin: true,
  66. rewrite: (p) => p.replace(/^\/dev-api\/baidu-chat/, '')
  67. }
  68. }
  69. },
  70. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  71. css: {
  72. postcss: {
  73. plugins: [{
  74. postcssPlugin: 'internal:charset-removal',
  75. AtRule: {
  76. charset: (atRule) => {
  77. if (atRule.name === 'charset') {
  78. atRule.remove();
  79. }
  80. }
  81. }
  82. }]
  83. }
  84. },
  85. build: {
  86. minify: 'terser',
  87. terserOptions: {
  88. compress: {
  89. //生产环境时移除console
  90. // drop_console: true,
  91. // drop_debugger: true,
  92. },
  93. }
  94. },
  95. }
  96. })