vite.config.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: 81,
  36. host: true,
  37. open: true,
  38. proxy: {
  39. // https://cn.vitejs.dev/config/#server-proxy
  40. '/dev-api': {
  41. // target: 'http://192.168.1.28:8080/',
  42. // target: 'http://8.142.173.95:19527/',
  43. target:'http://192.168.1.28:8080/',
  44. changeOrigin: true,
  45. rewrite: (p) => p.replace(/^\/dev-api/, '')
  46. },
  47. //websocket代理
  48. '/websocket': {
  49. // target:'ws://8.142.173.95:19527/websocket',
  50. // target:'ws://192.168.1.28:8080/websocket',
  51. target:'ws://192.168.1.11:8080/websocket',
  52. changeOrigin: true,
  53. rewrite: (p) => p.replace(/^\/websocket/, '')
  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. })