vite.config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. changeOrigin: true,
  44. rewrite: (p) => p.replace(/^\/dev-api/, '')
  45. },
  46. //websocket代理
  47. '/websocket': {
  48. // target: 'ws://192.168.1.28:8080/websocket',
  49. target:'ws://8.142.173.95:19527/websocket',
  50. changeOrigin: true,
  51. rewrite: (p) => p.replace(/^\/websocket/, '')
  52. }
  53. }
  54. },
  55. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  56. css: {
  57. postcss: {
  58. plugins: [{
  59. postcssPlugin: 'internal:charset-removal',
  60. AtRule: {
  61. charset: (atRule) => {
  62. if (atRule.name === 'charset') {
  63. atRule.remove();
  64. }
  65. }
  66. }
  67. }]
  68. }
  69. }
  70. }
  71. })