config.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  7. const { REACT_APP_ENV } = process.env
  8. const prodGzipList = ['js', 'css', 'html']
  9. export default defineConfig({
  10. plugins: [require.resolve('@umijs/plugins/dist/unocss')],
  11. npmClient: 'pnpm',
  12. hash: true,
  13. antd: {},
  14. model: {},
  15. moment2dayjs: {},
  16. request: {},
  17. initialState: {},
  18. access: {},
  19. dva: {},
  20. srcTranspiler: 'esbuild',
  21. mfsu: {},
  22. fastRefresh: true,
  23. unocss: {
  24. watch: ['src/{pages,components}/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
  25. },
  26. // Fast Refresh 热更新
  27. theme: {},
  28. layout: {},
  29. // clickToComponent: {},
  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. ['babel-plugin-import', { libraryName: 'antd', libraryDirectory: 'es', style: true }, 'antd'],
  43. [
  44. 'babel-plugin-import',
  45. { libraryName: '@formily/antd', libraryDirectory: 'es', style: true },
  46. '@formily/antd'
  47. ]
  48. ],
  49. chainWebpack(config, { env }) {
  50. if (env === 'production') {
  51. config.plugin('compression-webpack-plugin').use(
  52. new CompressionWebpackPlugin({
  53. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  54. algorithm: 'gzip', // 指定生成gzip格式
  55. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  56. threshold: 10000, //对超过10k的数据进行压缩
  57. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  58. })
  59. )
  60. }
  61. }
  62. })