vite.config.build.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. },
  27. },
  28. external: /\.\/static.*/,
  29. },
  30. },
  31. server: {
  32. port: 7771,
  33. proxy: {
  34. '/api': {
  35. target: 'https://php.mmxiaowu.com',
  36. changeOrigin: true,
  37. rewrite: (path: string) => path.replace(/^\/api/, '/api'),
  38. },
  39. },
  40. /**
  41. * 预热常用文件
  42. * @see https://cn.vitejs.dev/guide/performance#warm-up-frequently-used-files
  43. */
  44. warmup: {
  45. clientFiles: ['./src/main.ts', './src/views/**/*.vue'],
  46. },
  47. },
  48. }
  49. export default config