You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.8 KiB

  1. import { getPluginsList } from "./build/plugins";
  2. import { include, exclude } from "./build/optimize";
  3. import { type UserConfigExport, type ConfigEnv, loadEnv } from "vite";
  4. import {
  5. root,
  6. alias,
  7. warpperEnv,
  8. pathResolve,
  9. __APP_INFO__
  10. } from "./build/utils";
  11. export default ({ mode }: ConfigEnv): UserConfigExport => {
  12. const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } =
  13. warpperEnv(loadEnv(mode, root));
  14. return {
  15. base: VITE_PUBLIC_PATH,
  16. root,
  17. resolve: {
  18. alias
  19. },
  20. // 服务端渲染
  21. server: {
  22. // 端口号
  23. port: VITE_PORT,
  24. host: "0.0.0.0",
  25. // 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
  26. proxy: {},
  27. // 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
  28. warmup: {
  29. clientFiles: ["./index.html", "./src/{views,components}/*"]
  30. }
  31. },
  32. plugins: getPluginsList(VITE_CDN, VITE_COMPRESSION),
  33. // https://cn.vitejs.dev/config/dep-optimization-options.html#dep-optimization-options
  34. optimizeDeps: {
  35. include,
  36. exclude
  37. },
  38. build: {
  39. // https://cn.vitejs.dev/guide/build.html#browser-compatibility
  40. target: "es2015",
  41. sourcemap: false,
  42. // 消除打包大小超过500kb警告
  43. chunkSizeWarningLimit: 4000,
  44. rollupOptions: {
  45. input: {
  46. index: pathResolve("./index.html", import.meta.url)
  47. },
  48. // 静态资源分类打包
  49. output: {
  50. chunkFileNames: "static/js/[name]-[hash].js",
  51. entryFileNames: "static/js/[name]-[hash].js",
  52. assetFileNames: "static/[ext]/[name]-[hash].[ext]"
  53. }
  54. }
  55. },
  56. define: {
  57. __INTLIFY_PROD_DEVTOOLS__: false,
  58. __APP_INFO__: JSON.stringify(__APP_INFO__)
  59. }
  60. };
  61. };