config.js 3.8 KB

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