vite.config.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { UserConfig, ConfigEnv, loadEnv, defineConfig } from 'vite';
  2. import createPlugins from './vite/plugins';
  3. import path from 'path';
  4. export default defineConfig(({ mode, command }: ConfigEnv): UserConfig => {
  5. const env = loadEnv(mode, process.cwd());
  6. return {
  7. // 部署生产环境和开发环境下的URL。
  8. // 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
  9. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  10. base: env.VITE_APP_CONTEXT_PATH,
  11. resolve: {
  12. alias: {
  13. '~': path.resolve(__dirname, './'),
  14. '@': path.resolve(__dirname, './src')
  15. },
  16. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  17. },
  18. // https://cn.vitejs.dev/config/#resolve-extensions
  19. plugins: createPlugins(env, command === 'build'),
  20. server: {
  21. host: '0.0.0.0',
  22. port: Number(env.VITE_APP_PORT),
  23. open: true,
  24. proxy: {
  25. [env.VITE_APP_BASE_API]: {
  26. target: 'http://localhost:8080',
  27. changeOrigin: true,
  28. ws: true,
  29. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  30. }
  31. }
  32. },
  33. css: {
  34. preprocessorOptions: {
  35. scss: {
  36. javascriptEnabled: true
  37. }
  38. },
  39. postcss: {
  40. plugins: [
  41. {
  42. postcssPlugin: 'internal:charset-removal',
  43. AtRule: {
  44. charset: (atRule) => {
  45. if (atRule.name === 'charset') {
  46. atRule.remove();
  47. }
  48. }
  49. }
  50. }
  51. ]
  52. }
  53. },
  54. // 预编译
  55. optimizeDeps: {
  56. include: [
  57. 'vue',
  58. 'vue-router',
  59. 'pinia',
  60. 'axios',
  61. '@vueuse/core',
  62. 'echarts',
  63. 'vue-i18n',
  64. '@vueup/vue-quill',
  65. 'bpmn-js/lib/Viewer',
  66. 'bpmn-js/lib/Modeler.js',
  67. 'bpmn-js-properties-panel',
  68. 'min-dash',
  69. 'diagram-js/lib/navigation/movecanvas',
  70. 'diagram-js/lib/navigation/zoomscroll',
  71. 'bpmn-js/lib/features/palette/PaletteProvider',
  72. 'bpmn-js/lib/features/context-pad/ContextPadProvider',
  73. 'diagram-js/lib/draw/BaseRenderer',
  74. 'tiny-svg',
  75. 'image-conversion',
  76. 'element-plus/es/components/text/style/css',
  77. 'element-plus/es/components/collapse-item/style/css',
  78. 'element-plus/es/components/collapse/style/css',
  79. 'element-plus/es/components/space/style/css',
  80. 'element-plus/es/components/container/style/css',
  81. 'element-plus/es/components/aside/style/css',
  82. 'element-plus/es/components/main/style/css',
  83. 'element-plus/es/components/header/style/css',
  84. 'element-plus/es/components/button-group/style/css',
  85. 'element-plus/es/components/radio-button/style/css',
  86. 'element-plus/es/components/checkbox-group/style/css',
  87. 'element-plus/es/components/form/style/css',
  88. 'element-plus/es/components/form-item/style/css',
  89. 'element-plus/es/components/button/style/css',
  90. 'element-plus/es/components/input/style/css',
  91. 'element-plus/es/components/input-number/style/css',
  92. 'element-plus/es/components/switch/style/css',
  93. 'element-plus/es/components/upload/style/css',
  94. 'element-plus/es/components/menu/style/css',
  95. 'element-plus/es/components/col/style/css',
  96. 'element-plus/es/components/icon/style/css',
  97. 'element-plus/es/components/row/style/css',
  98. 'element-plus/es/components/tag/style/css',
  99. 'element-plus/es/components/dialog/style/css',
  100. 'element-plus/es/components/loading/style/css',
  101. 'element-plus/es/components/radio/style/css',
  102. 'element-plus/es/components/radio-group/style/css',
  103. 'element-plus/es/components/popover/style/css',
  104. 'element-plus/es/components/scrollbar/style/css',
  105. 'element-plus/es/components/tooltip/style/css',
  106. 'element-plus/es/components/dropdown/style/css',
  107. 'element-plus/es/components/dropdown-menu/style/css',
  108. 'element-plus/es/components/dropdown-item/style/css',
  109. 'element-plus/es/components/sub-menu/style/css',
  110. 'element-plus/es/components/menu-item/style/css',
  111. 'element-plus/es/components/divider/style/css',
  112. 'element-plus/es/components/card/style/css',
  113. 'element-plus/es/components/link/style/css',
  114. 'element-plus/es/components/breadcrumb/style/css',
  115. 'element-plus/es/components/breadcrumb-item/style/css',
  116. 'element-plus/es/components/table/style/css',
  117. 'element-plus/es/components/tree-select/style/css',
  118. 'element-plus/es/components/table-column/style/css',
  119. 'element-plus/es/components/select/style/css',
  120. 'element-plus/es/components/option/style/css',
  121. 'element-plus/es/components/pagination/style/css',
  122. 'element-plus/es/components/tree/style/css',
  123. 'element-plus/es/components/alert/style/css',
  124. 'element-plus/es/components/checkbox/style/css',
  125. 'element-plus/es/components/date-picker/style/css',
  126. 'element-plus/es/components/transfer/style/css',
  127. 'element-plus/es/components/tabs/style/css',
  128. 'element-plus/es/components/image/style/css',
  129. 'element-plus/es/components/tab-pane/style/css'
  130. ]
  131. }
  132. };
  133. });