vite.config.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { defineConfig, splitVendorChunkPlugin } from "vite";
  2. import legacy from "@vitejs/plugin-legacy";
  3. import { fileURLToPath, URL } from "url";
  4. import react from "@vitejs/plugin-react";
  5. import { visualizer } from "rollup-plugin-visualizer";
  6. import image from "@rollup/plugin-image";
  7. /**
  8. * @type {import('vite').UserConfig}
  9. * @see https://vitejs.dev/config/
  10. */
  11. export default defineConfig({
  12. plugins: [
  13. react(),
  14. visualizer(),
  15. image(),
  16. splitVendorChunkPlugin(),
  17. legacy({
  18. targets: ["defaults", "not IE 11"]
  19. })
  20. ],
  21. resolve: {
  22. alias: {
  23. "@": fileURLToPath(new URL("./src", import.meta.url)),
  24. lodash: "lodash-es"
  25. }
  26. },
  27. server: {
  28. port: 3000
  29. },
  30. build: {
  31. outDir: "dist",
  32. assetsDir: "static",
  33. cssCodeSplit: true,
  34. chunkSizeWarningLimit: 500,
  35. modulePreload: {
  36. polyfill: true
  37. },
  38. rollupOptions: {
  39. output: {
  40. chunkFileNames: "static/js/[name].[hash:12].chunk.js",
  41. entryFileNames: "static/js/[name].[hash:12].js",
  42. assetFileNames: (info) => {
  43. if (["css", "sass", "scss"].some((ext) => info.name?.endsWith("." + ext))) {
  44. return "static/css/[name].[hash:12].[ext]";
  45. }
  46. if (["png", "jpg", "jpeg", "gif", "svg"].some((ext) => info.name?.endsWith("." + ext))) {
  47. return "static/img/[name].[hash:12].[ext]";
  48. }
  49. return "static/media/[name].[hash:12].[ext]";
  50. }
  51. }
  52. }
  53. }
  54. });