vite.config.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
  16. },
  17. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  18. },
  19. // https://cn.vitejs.dev/config/#resolve-extensions
  20. plugins: createPlugins(env, command === 'build'),
  21. server: {
  22. host: '0.0.0.0',
  23. port: Number(env.VITE_APP_PORT),
  24. open: true,
  25. proxy: {
  26. [env.VITE_APP_BASE_API]: {
  27. target: 'http://localhost:8080',
  28. changeOrigin: true,
  29. ws: true,
  30. rewrite: (path) => path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
  31. }
  32. }
  33. },
  34. css: {
  35. preprocessorOptions: {
  36. scss: {
  37. javascriptEnabled: true
  38. }
  39. },
  40. postcss: {
  41. plugins: [
  42. {
  43. postcssPlugin: 'internal:charset-removal',
  44. AtRule: {
  45. charset: (atRule) => {
  46. if (atRule.name === 'charset') {
  47. atRule.remove();
  48. }
  49. }
  50. }
  51. }
  52. ]
  53. }
  54. },
  55. // 预编译
  56. optimizeDeps: {
  57. include: [
  58. 'vue',
  59. 'vue-router',
  60. 'pinia',
  61. 'axios',
  62. '@vueuse/core',
  63. 'path-to-regexp',
  64. 'echarts',
  65. '@wangeditor/editor',
  66. '@wangeditor/editor-for-vue',
  67. 'vue-i18n',
  68. '@vueup/vue-quill',
  69. '@iconify/iconify',
  70. 'element-plus/es/components/form/style/css',
  71. 'element-plus/es/components/form-item/style/css',
  72. 'element-plus/es/components/button/style/css',
  73. 'element-plus/es/components/input/style/css',
  74. 'element-plus/es/components/input-number/style/css',
  75. 'element-plus/es/components/switch/style/css',
  76. 'element-plus/es/components/upload/style/css',
  77. 'element-plus/es/components/menu/style/css',
  78. 'element-plus/es/components/col/style/css',
  79. 'element-plus/es/components/icon/style/css',
  80. 'element-plus/es/components/row/style/css',
  81. 'element-plus/es/components/tag/style/css',
  82. 'element-plus/es/components/dialog/style/css',
  83. 'element-plus/es/components/loading/style/css',
  84. 'element-plus/es/components/radio/style/css',
  85. 'element-plus/es/components/radio-group/style/css',
  86. 'element-plus/es/components/popover/style/css',
  87. 'element-plus/es/components/scrollbar/style/css',
  88. 'element-plus/es/components/tooltip/style/css',
  89. 'element-plus/es/components/dropdown/style/css',
  90. 'element-plus/es/components/dropdown-menu/style/css',
  91. 'element-plus/es/components/dropdown-item/style/css',
  92. 'element-plus/es/components/sub-menu/style/css',
  93. 'element-plus/es/components/menu-item/style/css',
  94. 'element-plus/es/components/divider/style/css',
  95. 'element-plus/es/components/card/style/css',
  96. 'element-plus/es/components/link/style/css',
  97. 'element-plus/es/components/breadcrumb/style/css',
  98. 'element-plus/es/components/breadcrumb-item/style/css',
  99. 'element-plus/es/components/table/style/css',
  100. 'element-plus/es/components/tree-select/style/css',
  101. 'element-plus/es/components/table-column/style/css',
  102. 'element-plus/es/components/select/style/css',
  103. 'element-plus/es/components/option/style/css',
  104. 'element-plus/es/components/pagination/style/css',
  105. 'element-plus/es/components/tree/style/css',
  106. 'element-plus/es/components/alert/style/css',
  107. 'element-plus/es/components/checkbox/style/css',
  108. 'element-plus/es/components/date-picker/style/css',
  109. 'element-plus/es/components/transfer/style/css',
  110. 'element-plus/es/components/tabs/style/css',
  111. 'element-plus/es/components/image/style/css',
  112. 'element-plus/es/components/tab-pane/style/css'
  113. ]
  114. }
  115. };
  116. });