config.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // https://umijs.org/config/
  2. import { defineConfig } from '@umijs/max'
  3. import defaultSettings from './defaultSettings'
  4. import proxy from './proxy'
  5. import routes from './routes'
  6. const CompressionPlugin = require('compression-webpack-plugin')
  7. const prodGzipList = ['js', 'css', 'html']
  8. const { REACT_APP_ENV } = process.env
  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. mfsu: {
  21. chainWebpack(config, { env }) {
  22. if (env === 'production') {
  23. // config.merge({
  24. // optimization: {
  25. // minimize: true,
  26. // splitChunks: {
  27. // chunks: 'all',
  28. // minSize: 30000,
  29. // minChunks: 2,
  30. // automaticNameDelimiter: '.',
  31. // cacheGroups: {
  32. // vendor: {
  33. // name: 'vendors',
  34. // test: ({ resource }) => /[\\/]node_modules[\\/]/.test(resource),
  35. // chunks: 'all',
  36. // priority: 20
  37. // }
  38. // }
  39. // }
  40. // }
  41. // })
  42. config.plugin('compression-webpack-plugin').use(
  43. new CompressionPlugin({
  44. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  45. algorithm: 'gzip', // 指定生成gzip格式
  46. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  47. threshold: 10000, //对超过10k的数据进行压缩
  48. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  49. })
  50. )
  51. }
  52. }
  53. },
  54. srcTranspiler: 'esbuild',
  55. fastRefresh: true,
  56. unocss: {
  57. watch: ['src/pages/**/*.{jsx,tsx,less}', 'src/components/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
  58. },
  59. // Fast Refresh 热更新
  60. theme: { 'primary-color': '#886ab5' },
  61. layout: {},
  62. locale: {
  63. default: 'zh-CN',
  64. antd: false,
  65. baseNavigator: false
  66. },
  67. define: { REACT_APP_ENV: REACT_APP_ENV || false },
  68. targets: { ie: 11 },
  69. routes,
  70. title: false,
  71. proxy: proxy[REACT_APP_ENV || 'dev'],
  72. manifest: { basePath: '/' },
  73. extraBabelPlugins: [
  74. '@babel/plugin-proposal-nullish-coalescing-operator',
  75. '@babel/plugin-proposal-optional-chaining',
  76. [
  77. 'import',
  78. {
  79. libraryName: '@icon-park/react',
  80. libraryDirectory: 'es/icons',
  81. camel2DashComponentName: false
  82. },
  83. '@icon-park/react'
  84. ],
  85. [
  86. 'import',
  87. {
  88. libraryName: 'antd',
  89. libraryDirectory: 'es',
  90. style: 'less'
  91. },
  92. 'antd'
  93. ]
  94. ]
  95. // externals: {
  96. // react: 'React',
  97. // 'react-dom': 'ReactDOM'
  98. // },
  99. // headScripts:
  100. // process.env.NODE_ENV === 'development'
  101. // ? [
  102. // 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.development.js',
  103. // 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.development.js'
  104. // ]
  105. // : [
  106. // 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.production.min.js',
  107. // 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.production.min.js'
  108. // ],
  109. })