config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // https://umijs.org/config/
  2. import os from 'os';
  3. import pageRoutes from './router.config';
  4. import webpackPlugin from './plugin.config';
  5. import defaultSettings from '../src/defaultSettings';
  6. import slash from 'slash2';
  7. const { pwa, primaryColor } = defaultSettings;
  8. const { APP_TYPE, TEST } = process.env;
  9. const plugins = [
  10. [
  11. 'umi-plugin-react',
  12. {
  13. antd: true,
  14. dva: {
  15. hmr: true,
  16. },
  17. locale: {
  18. enable: true, // default false
  19. default: 'zh-CN', // default zh-CN
  20. baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
  21. },
  22. dynamicImport: {
  23. loadingComponent: './components/PageLoading/index',
  24. webpackChunkName: true,
  25. level: 3,
  26. },
  27. pwa: pwa
  28. ? {
  29. workboxPluginMode: 'InjectManifest',
  30. workboxOptions: {
  31. importWorkboxFrom: 'local',
  32. },
  33. }
  34. : false,
  35. ...(!TEST && os.platform() === 'darwin'
  36. ? {
  37. dll: {
  38. include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  39. exclude: ['@babel/runtime'],
  40. },
  41. hardSource: false,
  42. }
  43. : {}),
  44. },
  45. ],
  46. ];
  47. // 针对 preview.pro.ant.design 的 GA 统计代码
  48. // 业务上不需要这个
  49. if (APP_TYPE === 'site') {
  50. plugins.push([
  51. 'umi-plugin-ga',
  52. {
  53. code: 'UA-72788897-6',
  54. },
  55. ]);
  56. }
  57. export default {
  58. // add for transfer to umi
  59. plugins,
  60. define: {
  61. APP_TYPE: APP_TYPE || '',
  62. },
  63. treeShaking: true,
  64. targets: {
  65. ie: 11,
  66. },
  67. // 路由配置
  68. routes: pageRoutes,
  69. // Theme for antd
  70. // https://ant.design/docs/react/customize-theme-cn
  71. theme: {
  72. 'primary-color': primaryColor,
  73. },
  74. // proxy: {
  75. // '/server/api/': {
  76. // target: 'https://preview.pro.ant.design/',
  77. // changeOrigin: true,
  78. // pathRewrite: { '^/server': '' },
  79. // },
  80. // },
  81. ignoreMomentLocale: true,
  82. lessLoaderOptions: {
  83. javascriptEnabled: true,
  84. },
  85. disableRedirectHoist: true,
  86. cssLoaderOptions: {
  87. modules: true,
  88. getLocalIdent: (context, localIdentName, localName) => {
  89. if (
  90. context.resourcePath.includes('node_modules') ||
  91. context.resourcePath.includes('ant.design.pro.less') ||
  92. context.resourcePath.includes('global.less')
  93. ) {
  94. return localName;
  95. }
  96. const match = context.resourcePath.match(/src(.*)/);
  97. if (match && match[1]) {
  98. const antdProPath = match[1].replace('.less', '');
  99. const arr = slash(antdProPath)
  100. .split('/')
  101. .map(a => a.replace(/([A-Z])/g, '-$1'))
  102. .map(a => a.toLowerCase());
  103. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  104. }
  105. return localName;
  106. },
  107. },
  108. manifest: {
  109. basePath: '/',
  110. },
  111. chainWebpack: webpackPlugin,
  112. };