config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. nodeModulesTransform: {
  62. type: 'none'
  63. },
  64. fastRefresh: {},
  65. nodeModulesTransform: {
  66. type: 'none' // 提升编译速度加速,加速
  67. },
  68. extraBabelPlugins: [
  69. '@babel/plugin-proposal-nullish-coalescing-operator',
  70. '@babel/plugin-proposal-optional-chaining',
  71. [
  72. 'import',
  73. {
  74. libraryName: '@icon-park/react',
  75. libraryDirectory: 'es/icons',
  76. camel2DashComponentName: false
  77. }
  78. ]
  79. ],
  80. chainWebpack(config) {
  81. config.plugin('windicss').use(windicss)
  82. config.plugin('antd-dayjs-webpack-plugin').use(AntdDayjsWebpackPlugin)
  83. if (NODE_ENV === 'production') {
  84. config.merge({
  85. optimization: {
  86. minimize: true,
  87. splitChunks: {
  88. chunks: 'async',
  89. minSize: 30000,
  90. minChunks: 2,
  91. automaticNameDelimiter: '.',
  92. cacheGroups: {
  93. vendor: {
  94. name: 'vendors',
  95. test: /^.*node_modules[\\/](!lodash|antd).*$/,
  96. chunks: 'all',
  97. priority: 10
  98. },
  99. antd: {
  100. name: 'antd',
  101. test: /[\\/]node_modules[\\/]antd[\\/]/,
  102. chunks: 'all',
  103. priority: 9
  104. }
  105. }
  106. }
  107. }
  108. })
  109. config.plugin('compression-webpack-plugin').use(
  110. new CompressionWebpackPlugin({
  111. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  112. algorithm: 'gzip', // 指定生成gzip格式
  113. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  114. threshold: 5000, //对超过10k的数据进行压缩
  115. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  116. })
  117. )
  118. }
  119. //过滤掉momnet的那些不使用的国际化文件
  120. // config
  121. // .plugin('replace')
  122. // .use(require('webpack').ContextReplacementPlugin)
  123. // .tap(() => {
  124. // return [/moment[/\\]locale$/, /zh-cn/]
  125. // })
  126. }
  127. })