config.ts 2.1 KB

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