vite.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import {
  2. defineConfig,
  3. loadEnv
  4. } from 'vite'
  5. import path from 'path'
  6. import createVitePlugins from './vite/plugins'
  7. import { createHtmlPlugin } from 'vite-plugin-html';
  8. // https://vitejs.dev/config/
  9. export default defineConfig(({
  10. mode,
  11. command
  12. }) => {
  13. const env = loadEnv(mode, process.cwd())
  14. const { VITE_APP_ENV } = env
  15. return {
  16. // 部署生产环境和开发环境下的URL。
  17. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  18. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  19. base: VITE_APP_ENV === 'production' ? '/' : '/',
  20. plugins: [createHtmlPlugin({
  21. inject: {
  22. data: {
  23. title: env.VITE_APP_TITLE || '聚合智慧文档',
  24. path: env.VITE_APP_PATH +'/web-apps/apps/api/documents/api.js',
  25. },
  26. },
  27. }), createVitePlugins(env, command === 'build')],
  28. resolve: {
  29. // https://cn.vitejs.dev/config/#resolve-alias
  30. alias: {
  31. // 设置路径
  32. '~': path.resolve(__dirname, './'),
  33. // 设置别名
  34. '@': path.resolve(__dirname, './src')
  35. },
  36. // https://cn.vitejs.dev/config/#resolve-extensions
  37. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  38. },
  39. // vite 相关配置
  40. server: {
  41. port: 80,
  42. host: true,
  43. open: true,
  44. proxy: {
  45. // https://cn.vitejs.dev/config/#server-proxy
  46. '/dev-api': {
  47. // target: 'http://192.168.1.12:8080/',
  48. // target: 'http://192.168.1.88:8080/',
  49. target: 'http://192.168.101.99:8080/',
  50. // target: 'http://192.168.1.11:8080/',
  51. // target: 'http://localhost:8080/',
  52. // target:'http://192.168.1.28:8080/',
  53. // target:'http://8.142.173.95:19527',
  54. changeOrigin: true,
  55. rewrite: (p) => p.replace(/^\/dev-api/, '')
  56. },
  57. //websocket代理
  58. '/websocket': {
  59. // target:'ws://localhost:8080/websocket',
  60. // target:'ws://192.168.1.12:8080/websocket',
  61. target: 'ws://192.168.101.99:8080/websocket',
  62. // target:'ws://8.142.173.95:19527/websocket',
  63. // target:'ws://192.168.1.11:8080/websocket',
  64. changeOrigin: true,
  65. rewrite: (p) => p.replace(/^\/websocket/, '')
  66. }
  67. }
  68. },
  69. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  70. css: {
  71. postcss: {
  72. plugins: [{
  73. postcssPlugin: 'internal:charset-removal',
  74. AtRule: {
  75. charset: (atRule) => {
  76. if (atRule.name === 'charset') {
  77. atRule.remove();
  78. }
  79. }
  80. }
  81. }]
  82. }
  83. }
  84. }
  85. })