config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/**/*.{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. routes,
  38. title: false,
  39. proxy: proxy[REACT_APP_ENV || 'dev'],
  40. manifest: { basePath: '/' },
  41. extraBabelPlugins: [
  42. [
  43. 'import',
  44. {
  45. libraryName: '@icon-park/react',
  46. libraryDirectory: 'es/icons',
  47. camel2DashComponentName: false
  48. },
  49. '@icon-park/react'
  50. ],
  51. [
  52. 'import',
  53. {
  54. libraryName: 'antd',
  55. libraryDirectory: 'es',
  56. style: 'less'
  57. },
  58. 'antd'
  59. ]
  60. ],
  61. externals: REACT_APP_ENV !== 'dev' && {
  62. react: 'React',
  63. 'react-dom': 'ReactDOM'
  64. },
  65. chainWebpack(config, { env }) {
  66. config.plugin('compression-webpack-plugin').use(
  67. new CompressionPlugin({
  68. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  69. algorithm: 'gzip', // 指定生成gzip格式
  70. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  71. threshold: 10000, //对超过10k的数据进行压缩
  72. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  73. })
  74. )
  75. }
  76. })