config.js 3.3 KB

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