vite.config.js 2.3 KB

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