config.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { defineConfig } from '@umijs/max';
  2. import keepAlive from './keep-alive';
  3. import { extraMfsuExclude } from './mfsu.extensions';
  4. import { compressionPluginConfig, monacoPluginConfig } from './plugins';
  5. import proxy from './proxy';
  6. import routes from './routes';
  7. import { getBranchInfo } from './utils';
  8. const versionInfo = getBranchInfo();
  9. process.env.VERSION = JSON.stringify(versionInfo);
  10. const env = process.env.NODE_ENV;
  11. const isProduction = env === 'production';
  12. const t = Date.now();
  13. export default defineConfig({
  14. proxy: {
  15. ...proxy(process.env.PROXY_HOST)
  16. },
  17. history: {
  18. type: 'hash'
  19. },
  20. define: {
  21. 'process.env.ENABLE_ENTERPRISE': process.env.ENABLE_ENTERPRISE,
  22. 'process.env.APP_TITLE': process.env.APP_TITLE || '',
  23. 'process.env.ENABLE_PLAYGROUND': JSON.stringify(
  24. process.env.ENABLE_PLAYGROUND ?? 'true'
  25. )
  26. },
  27. analyze: {
  28. analyzerMode: 'server',
  29. analyzerPort: 8888,
  30. openAnalyzer: true,
  31. generateStatsFile: false,
  32. statsFilename: 'stats.json',
  33. logLevel: 'info',
  34. defaultSizes: 'parsed' // stat // gzip
  35. },
  36. mfsu: {
  37. exclude: ['lodash', 'ml-pca', ...extraMfsuExclude]
  38. },
  39. base: process.env.npm_config_base || '/',
  40. ...(isProduction
  41. ? {
  42. jsMinifierOptions: {
  43. compress: {
  44. drop_console: true,
  45. drop_debugger: true
  46. }
  47. },
  48. scripts: [
  49. {
  50. src: `/js/umi.${t}.js`
  51. }
  52. ],
  53. chainWebpack(config: any) {
  54. config.plugin('mini-css-extract-plugin').tap((args: any) => [
  55. {
  56. ...args[0],
  57. filename: `css/[name].${t}.css`,
  58. chunkFilename: `css/[name].${t}.chunk.css`
  59. }
  60. ]);
  61. config.output
  62. .filename(`js/[name].${t}.js`)
  63. .chunkFilename(`js/[name].${t}.chunk.js`);
  64. compressionPluginConfig(config);
  65. monacoPluginConfig(config);
  66. }
  67. }
  68. : {
  69. chainWebpack(config) {
  70. monacoPluginConfig(config);
  71. }
  72. }),
  73. favicons: ['/static/favicon.png'],
  74. jsMinifier: 'terser',
  75. cssMinifier: 'cssnano',
  76. presets: ['umi-presets-pro'],
  77. clickToComponent: {},
  78. antd: {
  79. style: 'less'
  80. },
  81. title: process.env.APP_TITLE || '网讯创智MaaS底座',
  82. hash: true,
  83. access: {},
  84. model: {},
  85. initialState: {},
  86. request: {},
  87. routePrefetch: {
  88. defaultPrefetch: 'intent'
  89. },
  90. keepalive: keepAlive,
  91. locale: {
  92. antd: true,
  93. baseNavigator: true,
  94. baseSeparator: '-',
  95. default: 'en-US',
  96. title: false,
  97. useLocalStorage: true
  98. },
  99. layout: false,
  100. routes,
  101. npmClient: 'pnpm'
  102. }) as any;