config.js 3.4 KB

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