vite.config.js 3.1 KB

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