config.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // https://umijs.org/config/
  2. import defaultSettings from './defaultSettings'
  3. import proxy from './proxy'
  4. import routes from './routes'
  5. import { defineConfig } from '@umijs/max'
  6. import { dirname } from 'path'
  7. const CompressionPlugin = require('compression-webpack-plugin')
  8. const prodGzipList = ['js', 'css', 'html']
  9. const { REACT_APP_ENV } = process.env
  10. export default defineConfig({
  11. plugins: [require.resolve('@umijs/plugins/dist/unocss')],
  12. npmClient: 'pnpm',
  13. hash: true,
  14. antd: {},
  15. model: {},
  16. moment2dayjs: {},
  17. request: {},
  18. initialState: {},
  19. access: {},
  20. dva: {},
  21. mfsu: {},
  22. srcTranspiler: 'esbuild',
  23. fastRefresh: true,
  24. unocss: {
  25. watch: ['src/{pages,components}/**/*.{jsx,tsx}'] // 添加其他包含 unocss 的 classname 的文件目录
  26. },
  27. // Fast Refresh 热更新
  28. theme: { 'primary-color': '#886ab5' },
  29. layout: {},
  30. deadCode: {}, // 检测未使用的文件和导出,仅在 build 阶段开启
  31. locale: {
  32. default: 'zh-CN',
  33. antd: false,
  34. baseNavigator: false
  35. },
  36. define: { REACT_APP_ENV: REACT_APP_ENV || false },
  37. targets: { ie: 11 },
  38. routes,
  39. title: false,
  40. proxy: proxy[REACT_APP_ENV || 'dev'],
  41. manifest: { basePath: '/' },
  42. extraBabelPlugins: [
  43. [
  44. 'import',
  45. {
  46. libraryName: '@icon-park/react',
  47. libraryDirectory: 'es/icons',
  48. camel2DashComponentName: false
  49. },
  50. '@icon-park/react'
  51. ],
  52. [
  53. 'import',
  54. {
  55. libraryName: 'antd',
  56. libraryDirectory: 'es',
  57. style: 'less'
  58. },
  59. 'antd'
  60. ]
  61. ],
  62. externals: {
  63. react: 'React',
  64. 'react-dom': 'ReactDOM'
  65. },
  66. chainWebpack(config, { env }) {
  67. config.plugin('compression-webpack-plugin').use(
  68. new CompressionPlugin({
  69. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  70. algorithm: 'gzip', // 指定生成gzip格式
  71. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  72. threshold: 10000, //对超过10k的数据进行压缩
  73. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  74. })
  75. )
  76. }
  77. })