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.1 KiB

  1. import dayjs from "dayjs";
  2. import { resolve } from "path";
  3. import pkg from "./package.json";
  4. import { warpperEnv } 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_CDN,
  26. VITE_PORT,
  27. VITE_LEGACY,
  28. VITE_COMPRESSION,
  29. VITE_PUBLIC_PATH
  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. // 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
  45. proxy: {}
  46. },
  47. plugins: getPluginsList(command, VITE_LEGACY, VITE_CDN, VITE_COMPRESSION),
  48. optimizeDeps: {
  49. include: ["pinia", "vue-i18n", "lodash-es", "@vueuse/core", "dayjs"],
  50. exclude: ["@pureadmin/theme/dist/browser-utils"]
  51. },
  52. build: {
  53. sourcemap: false,
  54. // 消除打包大小超过500kb警告
  55. chunkSizeWarningLimit: 4000,
  56. rollupOptions: {
  57. input: {
  58. index: pathResolve("index.html")
  59. },
  60. // 静态资源分类打包
  61. output: {
  62. chunkFileNames: "static/js/[name]-[hash].js",
  63. entryFileNames: "static/js/[name]-[hash].js",
  64. assetFileNames: "static/[ext]/[name]-[hash].[ext]"
  65. }
  66. }
  67. },
  68. define: {
  69. __INTLIFY_PROD_DEVTOOLS__: false,
  70. __APP_INFO__: JSON.stringify(__APP_INFO__)
  71. }
  72. };
  73. };