config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // https://umijs.org/config/
  2. const prodGzipList = ['js', 'css', 'html']
  3. import { defineConfig } from '@umijs/max'
  4. import defaultSettings from './defaultSettings'
  5. import proxy from './proxy'
  6. import routes from './routes'
  7. const { REACT_APP_ENV } = process.env
  8. export default defineConfig({
  9. plugins: [require.resolve('@umijs/plugins/dist/unocss')],
  10. npmClient: 'pnpm',
  11. hash: true,
  12. antd: { import: true },
  13. model: {},
  14. moment2dayjs: {},
  15. request: {},
  16. initialState: {},
  17. access: {},
  18. dva: {},
  19. mfsu: {},
  20. srcTranspiler: 'esbuild',
  21. fastRefresh: true,
  22. unocss: {
  23. watch: ['src/pages/**/*.{jsx,tsx,less}', 'src/components/**/*.{jsx,tsx,less}'] // 添加其他包含 unocss 的 classname 的文件目录
  24. },
  25. // Fast Refresh 热更新
  26. theme: { 'primary-color': '#886ab5' },
  27. layout: {},
  28. locale: {
  29. default: 'zh-CN',
  30. antd: false,
  31. baseNavigator: false
  32. },
  33. define: { REACT_APP_ENV: REACT_APP_ENV || false },
  34. history: { type: 'browser' },
  35. targets: { ie: 11 },
  36. routes,
  37. title: false,
  38. ignoreMomentLocale: true,
  39. proxy: proxy[REACT_APP_ENV || 'dev'],
  40. manifest: { basePath: '/' },
  41. extraBabelPlugins: [
  42. '@babel/plugin-proposal-nullish-coalescing-operator',
  43. '@babel/plugin-proposal-optional-chaining',
  44. [
  45. 'import',
  46. {
  47. libraryName: '@icon-park/react',
  48. libraryDirectory: 'es/icons',
  49. camel2DashComponentName: false
  50. },
  51. '@icon-park/react'
  52. ]
  53. ],
  54. externals: {
  55. react: 'React',
  56. 'react-dom': 'ReactDOM'
  57. },
  58. headScripts:
  59. process.env.NODE_ENV === 'development'
  60. ? [
  61. 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.development.js',
  62. 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.development.js'
  63. ]
  64. : [
  65. 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react.production.min.js',
  66. 'https://d2.smartcost.com.cn/cach/cld/react18.1.0/react-dom.production.min.js'
  67. ],
  68. // chainWebpack(config, { env }) {
  69. // config.plugin('windicss').use('windicss-webpack-plugin')
  70. // config.plugin('moment2dayjs').use('antd-dayjs-webpack-plugin')
  71. // if (env === 'production') {
  72. // config.merge({
  73. // optimization: {
  74. // minimize: true,
  75. // splitChunks: {
  76. // chunks: 'all',
  77. // minSize: 30000,
  78. // minChunks: 2,
  79. // automaticNameDelimiter: '.',
  80. // cacheGroups: {
  81. // vendor: {
  82. // name: 'vendors',
  83. // test: ({ resource }) => /^.(?=react).$/.test(resource),
  84. // chunks: 'all',
  85. // priority: 20
  86. // }
  87. // }
  88. // }
  89. // }
  90. // })
  91. // config.plugin('compression-webpack-plugin').use(
  92. // new CompressionWebpackPlugin({
  93. // // filename: 文件名称,这里我们不设置,让它保持和未压缩的文件同一个名称
  94. // algorithm: 'gzip', // 指定生成gzip格式
  95. // test: new RegExp('\\.(' + prodGzipList.join('|') + ')$'), // 匹配哪些格式文件需要压缩
  96. // threshold: 10000, //对超过10k的数据进行压缩
  97. // minRatio: 0.6 // 压缩比例,值为0 ~ 1
  98. // })
  99. // )
  100. // }
  101. // }
  102. })