config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // https://umijs.org/config/
  2. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  3. const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin')
  4. const prodGzipList = ['js', 'css']
  5. import { defineConfig } from 'umi'
  6. import defaultSettings from './defaultSettings'
  7. import proxy from './proxy'
  8. import routes from './routes'
  9. import windicss from 'windicss-webpack-plugin/dist/index'
  10. const { REACT_APP_ENV } = process.env
  11. export default defineConfig({
  12. hash: true,
  13. antd: {},
  14. layout: {
  15. // https://umijs.org/zh-CN/plugins/plugin-layout
  16. locale: true,
  17. siderWidth: 208,
  18. ...defaultSettings
  19. },
  20. dva: {
  21. hmr: true
  22. },
  23. history: {
  24. type: 'browser'
  25. },
  26. locale: {
  27. // default zh-CN
  28. default: 'zh-CN',
  29. antd: false,
  30. // default true, when it is true, will use `navigator.language` overwrite default
  31. baseNavigator: false
  32. },
  33. dynamicImport: {
  34. loading: '@/components/PageLoading/index'
  35. },
  36. targets: {
  37. ie: 11
  38. },
  39. terserOptions: {
  40. compress: {
  41. drop_console: REACT_APP_ENV === 'prod' ? true : false,
  42. drop_debugger: REACT_APP_ENV === 'prod' ? true : false
  43. }
  44. },
  45. // umi routes: https://umijs.org/docs/routing
  46. routes,
  47. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  48. theme: {
  49. 'primary-color': defaultSettings.primaryColor
  50. },
  51. title: false,
  52. ignoreMomentLocale: true,
  53. proxy: proxy[REACT_APP_ENV || 'dev'],
  54. manifest: {
  55. basePath: '/'
  56. },
  57. exportStatic: {},
  58. esbuild: {},
  59. fastRefresh: {},
  60. nodeModulesTransform: {
  61. type: 'none' // 提升编译速度加速,加速
  62. },
  63. extraBabelPlugins: [
  64. '@babel/plugin-proposal-nullish-coalescing-operator',
  65. '@babel/plugin-proposal-optional-chaining',
  66. [
  67. 'import',
  68. {
  69. libraryName: '@icon-park/react',
  70. libraryDirectory: 'es/icons',
  71. camel2DashComponentName: false
  72. }
  73. ]
  74. ],
  75. chainWebpack(config) {
  76. config.plugin('windicss').use(windicss)
  77. config.plugin('antd-dayjs-webpack-plugin').use(AntdDayjsWebpackPlugin)
  78. if (REACT_APP_ENV === 'prod') {
  79. config.merge({
  80. optimization: {
  81. minimize: true,
  82. splitChunks: {
  83. chunks: 'async',
  84. minSize: 30000,
  85. minChunks: 2,
  86. automaticNameDelimiter: '.',
  87. cacheGroups: {
  88. vendor: {
  89. name: 'vendors',
  90. test: /^.*node_modules[\\/](!lodash|antd).*$/,
  91. chunks: 'all',
  92. priority: 10
  93. },
  94. antd: {
  95. name: 'antd',
  96. test: /[\\/]node_modules[\\/]antd[\\/]/,
  97. chunks: 'all',
  98. priority: 9
  99. },
  100. lodash: {
  101. name: 'lodash',
  102. test: /[\\/]node_modules[\\/]lodash[\\/]/,
  103. chunks: 'all',
  104. priority: -2
  105. }
  106. }
  107. }
  108. }
  109. })
  110. config.plugin('compression-webpack-plugin').use(
  111. new CompressionWebpackPlugin({
  112. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  113. algorithm: 'gzip', // 指定生成gzip格式
  114. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  115. threshold: 5000, //对超过10k的数据进行压缩
  116. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  117. })
  118. )
  119. }
  120. //过滤掉momnet的那些不使用的国际化文件
  121. // config
  122. // .plugin('replace')
  123. // .use(require('webpack').ContextReplacementPlugin)
  124. // .tap(() => {
  125. // return [/moment[/\\]locale$/, /zh-cn/]
  126. // })
  127. }
  128. })