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