vite.config.build.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import type { BuildOptions, ServerOptions } from 'vite'
  2. import path from 'node:path'
  3. import { fileURLToPath } from 'node:url'
  4. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  5. const config: { server: ServerOptions, build: BuildOptions } = {
  6. build: {
  7. target: 'es2018',
  8. cssTarget: 'chrome79',
  9. minify: true,
  10. assetsInlineLimit: 4096,
  11. chunkSizeWarningLimit: 1000,
  12. outDir: 'dist',
  13. rollupOptions: {
  14. input: {
  15. main: path.resolve(__dirname, 'index.html'),
  16. },
  17. output: {
  18. manualChunks(id: string) {
  19. // 处理css分块
  20. if (id.includes('node_modules')) {
  21. return 'vendor'
  22. }
  23. if (id.includes('__uno.css')) {
  24. return 'unocss'
  25. }
  26. // 将i18n相关文件打包到单独的chunk
  27. if (id.includes('i18n/locales')) {
  28. return 'i18n'
  29. }
  30. },
  31. },
  32. external: /\.\/static.*/,
  33. },
  34. },
  35. server: {
  36. port: 7771,
  37. host: true,
  38. proxy: {
  39. '/api': {
  40. target: 'https://php.mmxiaowu.com',
  41. changeOrigin: true,
  42. rewrite: (path: string) => path.replace(/^\/api/, '/api'),
  43. },
  44. },
  45. /**
  46. * 预热常用文件
  47. * @see https://cn.vitejs.dev/guide/performance#warm-up-frequently-used-files
  48. */
  49. warmup: {
  50. clientFiles: ['./src/main.ts', './src/views/**/*.vue'],
  51. },
  52. },
  53. }
  54. export default config