vite.config.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/**/css'
  77. ]
  78. }
  79. };
  80. });