config.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. chunks: ['vendors', 'umi'],
  92. chainWebpack(config) {
  93. config.plugin('windicss').use(windicss)
  94. config.plugin('antd-dayjs-webpack-plugin').use(AntdDayjsWebpackPlugin)
  95. // if (REACT_APP_ENV === 'prod') {
  96. config.merge({
  97. optimization: {
  98. minimize: true,
  99. splitChunks: {
  100. chunks: 'async',
  101. minSize: 30000,
  102. minChunks: 3,
  103. automaticNameDelimiter: '.',
  104. cacheGroups: {
  105. react: {
  106. name: 'react',
  107. priority: 10,
  108. test: /[\\/]node_modules[\\/](react|react-dom|react-dom-router)[\\/]/
  109. },
  110. vendor: {
  111. name: 'vendors',
  112. test({ resource }) {
  113. return /[\\/]node_modules[\\/]/.test(resource)
  114. },
  115. priority: 10
  116. },
  117. antd: {
  118. name: 'antd',
  119. test: /[\\/]node_modules[\\/]antd/,
  120. chunks: 'all',
  121. priority: 9
  122. },
  123. chart: {
  124. name: 'chart',
  125. chunks: 'all',
  126. test: /[\\/]node_modules[\\/]@ant-design[\\/]charts/,
  127. priority: 11
  128. },
  129. icons: {
  130. name: 'icons',
  131. chunks: 'all',
  132. test: /[\\/]node_modules[\\/]@ant-design[\\/]icons/,
  133. priority: 10
  134. },
  135. 'pro-table': {
  136. name: 'pro-table',
  137. chunks: 'all',
  138. test: /[\\/]node_modules[\\/]@ant-design[\\/]pro-table/,
  139. priority: -1
  140. },
  141. 'pro-layout': {
  142. name: 'pro-layout',
  143. chunks: 'all',
  144. test: /[\\/]node_modules[\\/]@ant-design[\\/]pro-layout/,
  145. priority: -1
  146. },
  147. 'pro-form': {
  148. name: 'pro-form',
  149. chunks: 'all',
  150. test: /[\\/]node_modules[\\/]@ant-design[\\/]pro-form/,
  151. priority: 10
  152. },
  153. 'icon-park': {
  154. name: 'icon-park',
  155. chunks: 'all',
  156. test: /[\\/]node_modules[\\/]@icon-park[\\/]react/,
  157. priority: 10
  158. },
  159. 'arco-design': {
  160. name: 'arco-design',
  161. chunks: 'all',
  162. test: /[\\/]node_modules[\\/]@arco-design[\\/]web-react/,
  163. priority: 11
  164. },
  165. lodash: {
  166. name: 'lodash',
  167. test: /[\\/]node_modules[\\/]lodash-es[\\/]/,
  168. chunks: 'all',
  169. priority: -2
  170. },
  171. jsdk: {
  172. name: 'jsdk',
  173. chunks: 'initial',
  174. test: /[\\/]node_modules[\\/](dayjs|react-copy-to-clipboard|react-infinite-scroll-component)[\\/]/,
  175. priority: 11
  176. },
  177. markdown: {
  178. name: 'markdown',
  179. test: /[\\/]node_modules[\\/]react-markdown/,
  180. priority: 12
  181. },
  182. vditor: {
  183. name: 'vditor',
  184. test: /[\\/]node_modules[\\/]vditor[\\/]/,
  185. priority: 12
  186. },
  187. 'async-commons': {
  188. // 其余异步加载包
  189. chunks: 'async',
  190. minChunks: 2,
  191. name: 'async-commons',
  192. priority: 9
  193. },
  194. default: {
  195. name: 'default',
  196. minChunks: 1,
  197. priority: -1,
  198. reuseExistingChunk: true
  199. }
  200. }
  201. }
  202. }
  203. })
  204. // config.plugin('compression-webpack-plugin').use(
  205. // new CompressionWebpackPlugin({
  206. // // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  207. // algorithm: 'gzip', // 指定生成gzip格式
  208. // test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  209. // threshold: 5000, //对超过10k的数据进行压缩
  210. // minRatio: 0.6 // 压缩比例,值为0 ~ 1
  211. // })
  212. // )
  213. // }
  214. //过滤掉momnet的那些不使用的国际化文件
  215. // config
  216. // .plugin('replace')
  217. // .use(require('webpack').ContextReplacementPlugin)
  218. // .tap(() => {
  219. // return [/moment[/\\]locale$/, /zh-cn/]
  220. // })
  221. }
  222. })