vite.config.js 2.3 KB

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