config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // https://umijs.org/config/
  2. import CompressionWebpackPlugin from 'compression-webpack-plugin'
  3. const prodGzipList = ['js', 'css', 'html']
  4. import { defineConfig } from 'umi'
  5. import defaultSettings from './defaultSettings'
  6. import proxy from './proxy'
  7. import routes from './routes'
  8. const { REACT_APP_ENV } = process.env
  9. export default defineConfig({
  10. hash: true,
  11. antd: {},
  12. define: {
  13. REACT_APP_ENV: REACT_APP_ENV || false
  14. },
  15. layout: {
  16. // https://umijs.org/zh-CN/plugins/plugin-layout
  17. locale: true,
  18. siderWidth: 208,
  19. ...defaultSettings
  20. },
  21. dva: {
  22. hmr: true,
  23. disableModelsReExport: true,
  24. lazyLoad: true
  25. },
  26. history: {
  27. type: 'browser'
  28. },
  29. locale: {
  30. // default zh-CN
  31. default: 'zh-CN',
  32. antd: false,
  33. // default true, when it is true, will use `navigator.language` overwrite default
  34. baseNavigator: false
  35. },
  36. dynamicImport: {
  37. loading: '@/components/PageLoading/index'
  38. },
  39. targets: {
  40. ie: 11
  41. },
  42. externals: {
  43. react: 'React',
  44. 'react-dom': 'ReactDOM'
  45. },
  46. scripts:
  47. process.env.NODE_ENV === 'development'
  48. ? [
  49. 'https://d2.smartcost.com.cn/cach/cld/react.development.js',
  50. 'https://d2.smartcost.com.cn/cach/cld/react-dom.development.js'
  51. ]
  52. : [
  53. 'https://d2.smartcost.com.cn/cach/cld/react.production.min.js',
  54. 'https://d2.smartcost.com.cn/cach/cld/react-dom.production.min.js'
  55. ],
  56. routes,
  57. theme: {
  58. 'primary-color': defaultSettings.primaryColor
  59. },
  60. title: false,
  61. ignoreMomentLocale: true,
  62. proxy: proxy[REACT_APP_ENV || 'dev'],
  63. manifest: {
  64. basePath: '/'
  65. },
  66. exportStatic: {},
  67. esbuild: {},
  68. fastRefresh: {},
  69. nodeModulesTransform: {
  70. type: 'none' // 提升编译速度加速,加速
  71. },
  72. extraBabelPlugins: [
  73. '@babel/plugin-proposal-nullish-coalescing-operator',
  74. '@babel/plugin-proposal-optional-chaining',
  75. [
  76. 'import',
  77. {
  78. libraryName: '@icon-park/react',
  79. libraryDirectory: 'es/icons',
  80. camel2DashComponentName: false
  81. },
  82. '@icon-park/react'
  83. ]
  84. ],
  85. chainWebpack(config, { env }) {
  86. config.plugin('windicss').use('windicss-webpack-plugin')
  87. if (env === 'production') {
  88. config.merge({
  89. optimization: {
  90. minimize: true,
  91. splitChunks: {
  92. chunks: 'all',
  93. minSize: 30000,
  94. minChunks: 2,
  95. automaticNameDelimiter: '.',
  96. cacheGroups: {
  97. vendor: {
  98. name: 'vendors',
  99. test: ({ resource }) => /^.(?=react).$/.test(resource),
  100. chunks: 'all',
  101. priority: 20
  102. }
  103. }
  104. }
  105. }
  106. })
  107. config.plugin('compression-webpack-plugin').use(
  108. new CompressionWebpackPlugin({
  109. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  110. algorithm: 'gzip', // 指定生成gzip格式
  111. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  112. threshold: 10000, //对超过10k的数据进行压缩
  113. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  114. })
  115. )
  116. }
  117. //过滤掉momnet的那些不使用的国际化文件
  118. // config
  119. // .plugin('replace')
  120. // .use(require('webpack').ContextReplacementPlugin)
  121. // .tap(() => {
  122. // return [/moment[/\\]locale$/, /zh-cn/]
  123. // })
  124. }
  125. })