config.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. esbuild: true,
  23. strategy: 'normal'
  24. },
  25. fastRefresh: true,
  26. unocss: {
  27. watch: ['src/{pages,components}/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
  28. },
  29. // Fast Refresh 热更新
  30. theme: {},
  31. layout: {},
  32. // clickToComponent: {},
  33. locale: {
  34. default: 'zh-CN',
  35. antd: false,
  36. baseNavigator: false
  37. },
  38. define: { REACT_APP_ENV: REACT_APP_ENV || false },
  39. routes,
  40. title: false,
  41. proxy: proxy[REACT_APP_ENV || 'dev'],
  42. manifest: { basePath: '/' },
  43. extraBabelPlugins: [
  44. ['babel-plugin-import', { libraryName: 'antd', libraryDirectory: 'es', style: true }, 'antd'],
  45. [
  46. 'babel-plugin-import',
  47. { libraryName: '@formily/antd', libraryDirectory: 'es', style: true },
  48. '@formily/antd'
  49. ]
  50. ],
  51. chainWebpack(config, { env }) {
  52. if (env === 'production') {
  53. config.plugin('compression-webpack-plugin').use(
  54. new CompressionWebpackPlugin({
  55. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  56. algorithm: 'gzip', // 指定生成gzip格式
  57. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  58. threshold: 10000, //对超过10k的数据进行压缩
  59. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  60. })
  61. )
  62. }
  63. }
  64. })