vite.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import UnoCSS from 'unocss/vite'
  4. import { resolve } from 'path'
  5. import config from './src/config'
  6. import { vitePluginForArco } from '@arco-plugins/vite-vue'
  7. // https://vitejs.dev/config/
  8. export default defineConfig({
  9. css: {
  10. extract: true,
  11. },
  12. resolve: {
  13. alias: {
  14. '~src': `${resolve(__dirname, './src')}`,
  15. '~api': resolve(__dirname, './src/api/modules'),
  16. },
  17. },
  18. plugins: [
  19. vue(),
  20. UnoCSS(),
  21. vitePluginForArco({
  22. style: 'css'
  23. })
  24. ],
  25. build: {
  26. sourcemap: false,
  27. rollupOptions: {
  28. output: {
  29. manualChunks(id) {
  30. let libStr = '@vue,@arco-design,vue-router,pinia,js-fast-way,vuedraggable,split.js,hc-vue3-ui,nprogress'
  31. const libs = libStr.split(',')
  32. if (id.includes('node_modules')) {
  33. const arr = id.toString().split('node_modules/')[1].split('/')
  34. if (libs.indexOf(arr[0]) !== -1) {
  35. return '_' + arr[0]
  36. } else {
  37. return '__vendor'
  38. }
  39. }
  40. },
  41. chunkFileNames: 'static/js1/[name]-[hash].js',
  42. entryFileNames: 'static/js2/[name]-[hash].js',
  43. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  44. },
  45. },
  46. brotliSize: false, // 不统计
  47. target: 'esnext',
  48. },
  49. server: {
  50. ...config.vite,
  51. proxy: {
  52. '/api': {
  53. ws: true,
  54. changeOrigin: true,
  55. target: config.target,
  56. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  57. },
  58. },
  59. },
  60. })