config.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/**/*.{jsx,tsx,less}', 'src/components/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
  26. },
  27. // Fast Refresh 热更新
  28. theme: { 'primary-color': '#886ab5' },
  29. layout: {},
  30. locale: {
  31. default: 'zh-CN',
  32. antd: false,
  33. baseNavigator: false
  34. },
  35. define: { REACT_APP_ENV: REACT_APP_ENV || false },
  36. targets: { ie: 11 },
  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: {
  62. react: 'React',
  63. 'react-dom': 'ReactDOM'
  64. },
  65. chainWebpack(config, { env }) {
  66. if (env === 'production') {
  67. // config.merge({
  68. // optimization: {
  69. // minimize: true,
  70. // splitChunks: {
  71. // chunks: 'all',
  72. // minSize: 30000,
  73. // minChunks: 2,
  74. // automaticNameDelimiter: '.',
  75. // cacheGroups: {
  76. // vendor: {
  77. // name: 'vendors',
  78. // test: ({ resource }) => /[\\/]node_modules[\\/]/.test(resource),
  79. // chunks: 'all',
  80. // priority: 20
  81. // }
  82. // }
  83. // }
  84. // }
  85. // })
  86. config.plugin('compression-webpack-plugin').use(
  87. new CompressionPlugin({
  88. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  89. algorithm: 'gzip', // 指定生成gzip格式
  90. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  91. threshold: 10000, //对超过10k的数据进行压缩
  92. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  93. })
  94. )
  95. }
  96. }
  97. })