__unconfig_vite.config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. let __unconfig_data;
  2. let __unconfig_stub = function (data = {}) { __unconfig_data = data };
  3. __unconfig_stub.default = (data = {}) => { __unconfig_data = data };
  4. import type { UserConfig, ConfigEnv } from 'vite';
  5. import pkg from './package.json';
  6. import dayjs from 'dayjs';
  7. import { loadEnv } from 'vite';
  8. import { resolve } from 'path';
  9. import { generateModifyVars } from './build/generate/generateModifyVars';
  10. import { createProxy } from './build/vite/proxy';
  11. import { wrapperEnv } from './build/utils';
  12. import { createVitePlugins } from './build/vite/plugin';
  13. import { OUTPUT_DIR } from './build/constant';
  14. import { include, exclude } from './build/vite/optimize';
  15. function pathResolve(dir: string) {
  16. return resolve(process.cwd(), '.', dir);
  17. }
  18. const { dependencies, devDependencies, name, version } = pkg;
  19. const __APP_INFO__ = {
  20. pkg: { dependencies, devDependencies, name, version },
  21. lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  22. };
  23. const __unconfig_default = ({ command, mode }: ConfigEnv): UserConfig => {
  24. const root = process.cwd();
  25. const env = loadEnv(mode, root);
  26. // The boolean type read by loadEnv is a string. This function can be converted to boolean type
  27. const viteEnv = wrapperEnv(env);
  28. const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
  29. const isBuild = command === 'build';
  30. return {
  31. base: VITE_PUBLIC_PATH,
  32. root,
  33. server: {
  34. https: false,
  35. // Listening on all local IPs
  36. host: true,
  37. port: VITE_PORT,
  38. // Load proxy configuration from .env
  39. proxy: createProxy(VITE_PROXY),
  40. },
  41. resolve: {
  42. alias: [
  43. {
  44. find: 'vue-i18n',
  45. replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
  46. },
  47. // /@/xxxx => src/xxxx
  48. {
  49. find: /\/@\//,
  50. replacement: pathResolve('src') + '/',
  51. },
  52. {
  53. find: /\/@bpmn\//,
  54. replacement: pathResolve('src') + '/views/workflow/design/bpmn/',
  55. },
  56. // /#/xxxx => types/xxxx
  57. {
  58. find: /\/#\//,
  59. replacement: pathResolve('types') + '/',
  60. },
  61. ],
  62. },
  63. esbuild: {
  64. drop: VITE_DROP_CONSOLE ? ['console', 'debugger'] : [],
  65. },
  66. build: {
  67. target: 'es2015',
  68. cssTarget: 'chrome80',
  69. outDir: OUTPUT_DIR,
  70. // minify: 'terser',
  71. /**
  72. * 当 minify=“minify:'terser'” 解开注释
  73. * Uncomment when minify="minify:'terser'"
  74. */
  75. // terserOptions: {
  76. // compress: {
  77. // keep_infinity: true,
  78. // drop_console: VITE_DROP_CONSOLE,
  79. // },
  80. // },
  81. // Turning off brotliSize display can slightly reduce packaging time
  82. reportCompressedSize: false,
  83. chunkSizeWarningLimit: 2000,
  84. },
  85. define: {
  86. __APP_INFO__: JSON.stringify(__APP_INFO__),
  87. },
  88. css: {
  89. preprocessorOptions: {
  90. less: {
  91. modifyVars: generateModifyVars(),
  92. javascriptEnabled: true,
  93. },
  94. },
  95. },
  96. // The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
  97. plugins: createVitePlugins(viteEnv, isBuild),
  98. optimizeDeps: { include, exclude },
  99. };
  100. };
  101. if (typeof __unconfig_default === "function") __unconfig_default(...[{"command":"serve","mode":"development"}]);export default __unconfig_data;