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