vite.config.js 1.6 KB

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