config.js 3.9 KB

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