config.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // https://umijs.org/config/
  2. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  3. const prodGzipList = ['js', 'css']
  4. import { defineConfig } from 'umi'
  5. import defaultSettings from './defaultSettings'
  6. import proxy from './proxy'
  7. import routes from './routes'
  8. import windicss from 'windicss-webpack-plugin/dist/index'
  9. const { REACT_APP_ENV } = process.env
  10. export default defineConfig({
  11. hash: true,
  12. antd: {},
  13. dva: {
  14. hmr: true
  15. },
  16. history: {
  17. type: 'browser'
  18. },
  19. locale: {
  20. // default zh-CN
  21. default: 'zh-CN',
  22. antd: false,
  23. // default true, when it is true, will use `navigator.language` overwrite default
  24. baseNavigator: false
  25. },
  26. dynamicImport: {
  27. loading: '@/components/PageLoading/index'
  28. },
  29. targets: {
  30. ie: 11
  31. },
  32. // umi routes: https://umijs.org/docs/routing
  33. routes,
  34. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  35. theme: {
  36. 'primary-color': defaultSettings.primaryColor
  37. },
  38. title: false,
  39. ignoreMomentLocale: true,
  40. proxy: proxy[REACT_APP_ENV || 'dev'],
  41. manifest: {
  42. basePath: '/'
  43. },
  44. exportStatic: {},
  45. esbuild: {},
  46. fastRefresh: {},
  47. extraBabelPlugins: [
  48. '@babel/plugin-proposal-nullish-coalescing-operator',
  49. '@babel/plugin-proposal-optional-chaining',
  50. [
  51. 'import',
  52. {
  53. libraryName: '@icon-park/react',
  54. libraryDirectory: 'es/all',
  55. camel2DashComponentName: false
  56. }
  57. ]
  58. ],
  59. chainWebpack(config, { env }) {
  60. config.plugin('windicss').use(windicss)
  61. if (env === 'production') {
  62. config.plugin('compression-webpack-plugin').use(
  63. new CompressionWebpackPlugin({
  64. // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  65. algorithm: 'gzip', // 指定生成gzip格式
  66. test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  67. threshold: 1024, //对超过10k的数据进行压缩
  68. minRatio: 0.6 // 压缩比例,值为0 ~ 1
  69. })
  70. )
  71. }
  72. }
  73. })