config.js 3.7 KB

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