vite.config.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.1.88:8080/',
  50. target: 'http://192.168.101.99:8080/',
  51. // target: 'http://192.168.1.11:8080/',
  52. // target: 'http://localhost:8080/',
  53. // target:'http://192.168.1.28:8080/',
  54. //target:'http://8.142.173.95:19527',
  55. changeOrigin: true,
  56. rewrite: (p) => p.replace(/^\/dev-api/, '')
  57. },
  58. //websocket代理
  59. '/websocket': {
  60. // target:'ws://localhost:8080/websocket',
  61. // target:'ws://192.168.1.12:8080/websocket',
  62. //target:'ws://192.168.1.88:8080/websocket',
  63. //target:'ws://8.142.173.95:19527/websocket',
  64. target: 'ws://192.168.101.99:8080/websocket',
  65. // target:'ws://192.168.1.11:8080/websocket',
  66. changeOrigin: true,
  67. rewrite: (p) => p.replace(/^\/websocket/, '')
  68. }
  69. }
  70. },
  71. //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
  72. css: {
  73. postcss: {
  74. plugins: [{
  75. postcssPlugin: 'internal:charset-removal',
  76. AtRule: {
  77. charset: (atRule) => {
  78. if (atRule.name === 'charset') {
  79. atRule.remove();
  80. }
  81. }
  82. }
  83. }]
  84. }
  85. }
  86. }
  87. })