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.

78 lines
2.0 KiB

  1. import dayjs from "dayjs";
  2. import { resolve } from "path";
  3. import pkg from "./package.json";
  4. import { warpperEnv, regExps } from "./build";
  5. import { getPluginsList } from "./build/plugins";
  6. import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
  7. // 当前执行node命令时文件夹的地址(工作目录)
  8. const root: string = process.cwd();
  9. // 路径查找
  10. const pathResolve = (dir: string): string => {
  11. return resolve(__dirname, ".", dir);
  12. };
  13. // 设置别名
  14. const alias: Record<string, string> = {
  15. "/@": pathResolve("src"),
  16. "@build": pathResolve("build")
  17. };
  18. const { dependencies, devDependencies, name, version } = pkg;
  19. const __APP_INFO__ = {
  20. pkg: { dependencies, devDependencies, name, version },
  21. lastBuildTime: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
  22. };
  23. export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  24. const {
  25. VITE_PORT,
  26. VITE_LEGACY,
  27. VITE_PUBLIC_PATH,
  28. VITE_PROXY_DOMAIN,
  29. VITE_PROXY_DOMAIN_REAL
  30. } = warpperEnv(loadEnv(mode, root));
  31. return {
  32. base: VITE_PUBLIC_PATH,
  33. root,
  34. resolve: {
  35. alias
  36. },
  37. // 服务端渲染
  38. server: {
  39. // 是否开启 https
  40. https: false,
  41. // 端口号
  42. port: VITE_PORT,
  43. host: "0.0.0.0",
  44. // 本地跨域代理
  45. proxy:
  46. VITE_PROXY_DOMAIN_REAL.length > 0
  47. ? {
  48. [VITE_PROXY_DOMAIN]: {
  49. target: VITE_PROXY_DOMAIN_REAL,
  50. // ws: true,
  51. changeOrigin: true,
  52. rewrite: (path: string) => regExps(path, VITE_PROXY_DOMAIN)
  53. }
  54. }
  55. : null
  56. },
  57. plugins: getPluginsList(command, VITE_LEGACY),
  58. optimizeDeps: {
  59. include: ["pinia", "vue-i18n", "lodash-es", "@vueuse/core"],
  60. exclude: ["@pureadmin/theme/dist/browser-utils"]
  61. },
  62. build: {
  63. sourcemap: false,
  64. brotliSize: false,
  65. // 消除打包大小超过500kb警告
  66. chunkSizeWarningLimit: 4000
  67. },
  68. define: {
  69. __INTLIFY_PROD_DEVTOOLS__: false,
  70. __APP_INFO__: JSON.stringify(__APP_INFO__)
  71. }
  72. };
  73. };