config.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import defaultSettings from './defaultSettings'; // https://umijs.org/config/
  2. import slash from 'slash2';
  3. import themePluginConfig from './themePluginConfig';
  4. import routes from './routes';
  5. import proxy from './proxy';
  6. import webpackPlugin from './plugin.config';
  7. const { pwa } = defaultSettings; // preview.pro.ant.design only do not use in your production ;
  8. // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  9. const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV } = process.env;
  10. const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
  11. const plugins = [
  12. ['umi-plugin-antd-icon-config', {}],
  13. [
  14. 'umi-plugin-react',
  15. {
  16. antd: true,
  17. dva: {
  18. hmr: true,
  19. },
  20. locale: {
  21. // default false
  22. enable: true,
  23. // default zh-CN
  24. default: 'zh-CN',
  25. // default true, when it is true, will use `navigator.language` overwrite default
  26. baseNavigator: true,
  27. },
  28. dynamicImport: {
  29. loadingComponent: './components/PageLoading/index',
  30. webpackChunkName: true,
  31. level: 3,
  32. },
  33. pwa: pwa
  34. ? {
  35. workboxPluginMode: 'InjectManifest',
  36. workboxOptions: {
  37. importWorkboxFrom: 'local',
  38. },
  39. }
  40. : false, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
  41. // dll features https://webpack.js.org/plugins/dll-plugin/
  42. // dll: {
  43. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  44. // exclude: ['@babel/runtime', 'netlify-lambda'],
  45. // },
  46. },
  47. ],
  48. [
  49. 'umi-plugin-pro-block',
  50. {
  51. moveMock: false,
  52. moveService: false,
  53. modifyRequest: true,
  54. autoAddMenu: true,
  55. },
  56. ],
  57. ];
  58. if (isAntDesignProPreview) {
  59. // 针对 preview.pro.ant.design 的 GA 统计代码
  60. plugins.push([
  61. 'umi-plugin-ga',
  62. {
  63. code: 'UA-72788897-6',
  64. },
  65. ]);
  66. plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
  67. }
  68. export default {
  69. plugins,
  70. hash: true,
  71. targets: {
  72. ie: 11,
  73. },
  74. // umi routes: https://umijs.org/zh/guide/router.html
  75. routes,
  76. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  77. theme: {
  78. // ...darkTheme,
  79. 'primary-color': defaultSettings.primaryColor,
  80. },
  81. define: {
  82. REACT_APP_ENV: REACT_APP_ENV || false,
  83. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  84. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  85. },
  86. ignoreMomentLocale: true,
  87. lessLoaderOptions: {
  88. javascriptEnabled: true,
  89. },
  90. disableRedirectHoist: true,
  91. cssLoaderOptions: {
  92. modules: true,
  93. getLocalIdent: (context, _, localName) => {
  94. if (
  95. context.resourcePath.includes('node_modules') ||
  96. context.resourcePath.includes('ant.design.pro.less') ||
  97. context.resourcePath.includes('global.less')
  98. ) {
  99. return localName;
  100. }
  101. const match = context.resourcePath.match(/src(.*)/);
  102. if (match && match[1]) {
  103. const antdProPath = match[1].replace('.less', '');
  104. const arr = slash(antdProPath)
  105. .split('/')
  106. .map((a) => a.replace(/([A-Z])/g, '-$1'))
  107. .map((a) => a.toLowerCase());
  108. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  109. }
  110. return localName;
  111. },
  112. },
  113. manifest: {
  114. basePath: '/',
  115. },
  116. proxy: proxy[REACT_APP_ENV || 'dev'],
  117. chainWebpack: webpackPlugin,
  118. };