vite.config.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import ViteComponents from 'unplugin-vue-components/vite'
  4. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
  5. import DefineOptions from 'unplugin-vue-define-options/vite'
  6. import { chunkSplitPlugin } from 'vite-plugin-chunk-split';
  7. import { resolve } from 'path'
  8. // const proxy = {
  9. // '/api': {
  10. // target: 'https://v4-test.4dkankan.com/',
  11. // changeOrigin: true,
  12. // rewrite: path => path.replace(/^\/api/, '')
  13. // }
  14. // }
  15. // https://vitejs.dev/config/
  16. export default ({ mode }) =>
  17. defineConfig({
  18. base: './',
  19. plugins: [
  20. vue(),
  21. DefineOptions(),
  22. ViteComponents({
  23. resolvers: [
  24. AntDesignVueResolver({ resolveIcons: true, importStyle: 'less' })
  25. ],
  26. dts: 'src/components.d.ts'
  27. }),
  28. chunkSplitPlugin({
  29. strategy: 'default',
  30. customSplitting: {
  31. // `react` and `react-dom` 会被打包到一个名为`render-vendor`的 chunk 里面(包括它们的一些依赖,如 object-assign)
  32. 'vue-vendor': ['vue','pinia','vue-i18n','vue-router'],
  33. 'dept-vendor': ['ant-design-vue', '@ant-design/icons-vue'],
  34. // 源码中 utils 目录的代码都会打包进 `utils` 这个 chunk 中
  35. 'utils': ['echarts', 'lodash-es','vue3-autocounter']
  36. }
  37. })
  38. ],
  39. css: {
  40. preprocessorOptions: {
  41. less: {
  42. javascriptEnabled: true,
  43. modifyVars: {
  44. 'primary-color': '#0076F6',
  45. 'link-color': '#0076F6',
  46. 'border-radius-base': '2px'
  47. }
  48. }
  49. }
  50. },
  51. resolve: {
  52. alias: [
  53. {
  54. find: 'vue-i18n',
  55. replacement: 'vue-i18n/dist/vue-i18n.cjs.js'
  56. },
  57. {
  58. find: '@',
  59. replacement: resolve(__dirname, './src')
  60. },
  61. {
  62. find: '#',
  63. replacement: resolve(__dirname, './types')
  64. }
  65. ]
  66. },
  67. server: {
  68. host: '0.0.0.0',
  69. port: 5173,
  70. open: true,
  71. proxy: {
  72. '/api': {
  73. target: loadEnv(mode, process.cwd()).VITE_BASE_API_URL,
  74. changeOrigin: true,
  75. rewrite: path => path.replace(/^\/api/, '')
  76. }
  77. }
  78. },
  79. })