config.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // https://umijs.org/config/
  2. import os from 'os';
  3. import slash from 'slash2';
  4. import { IPlugin, IConfig } from 'umi-types';
  5. import defaultSettings from './defaultSettings';
  6. import webpackPlugin from './plugin.config';
  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: IPlugin[] = [
  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. 'umi-plugin-pro-block',
  49. {
  50. moveMock: false,
  51. moveService: false,
  52. modifyRequest: true,
  53. autoAddMenu: true,
  54. },
  55. ],
  56. ];
  57. // 针对 preview.pro.ant.design 的 GA 统计代码
  58. // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  59. if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
  60. plugins.push([
  61. 'umi-plugin-ga',
  62. {
  63. code: 'UA-72788897-6',
  64. },
  65. ]);
  66. }
  67. export default {
  68. // add for transfer to umi
  69. plugins,
  70. define: {
  71. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  72. 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 专用环境变量,请不要在你的项目中使用它。
  73. },
  74. treeShaking: true,
  75. targets: {
  76. ie: 11,
  77. },
  78. devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
  79. // 路由配置
  80. routes: [
  81. {
  82. path: '/user',
  83. components: ['../layouts/UserLayout'],
  84. routes: [],
  85. },
  86. {
  87. path: '/',
  88. component: '../layouts/BasicLayout',
  89. Routes: ['src/pages/Authorized'],
  90. authority: ['admin', 'user'],
  91. routes: [
  92. {
  93. path: '/analysis',
  94. name: 'Analysis',
  95. icon: 'dashboard',
  96. component: './analysis',
  97. },
  98. ],
  99. },
  100. ],
  101. // Theme for antd
  102. // https://ant.design/docs/react/customize-theme-cn
  103. theme: {
  104. 'primary-color': primaryColor,
  105. },
  106. // proxy: {
  107. // '/server/api/': {
  108. // target: 'https://preview.pro.ant.design/',
  109. // changeOrigin: true,
  110. // pathRewrite: { '^/server': '' },
  111. // },
  112. // },
  113. ignoreMomentLocale: true,
  114. lessLoaderOptions: {
  115. javascriptEnabled: true,
  116. },
  117. disableRedirectHoist: true,
  118. cssLoaderOptions: {
  119. modules: true,
  120. getLocalIdent: (context, localIdentName, localName) => {
  121. if (
  122. context.resourcePath.includes('node_modules') ||
  123. context.resourcePath.includes('ant.design.pro.less') ||
  124. context.resourcePath.includes('global.less')
  125. ) {
  126. return localName;
  127. }
  128. const match = context.resourcePath.match(/src(.*)/);
  129. if (match && match[1]) {
  130. const antdProPath = match[1].replace('.less', '');
  131. const arr = slash(antdProPath)
  132. .split('/')
  133. .map(a => a.replace(/([A-Z])/g, '-$1'))
  134. .map(a => a.toLowerCase());
  135. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  136. }
  137. return localName;
  138. },
  139. },
  140. manifest: {
  141. basePath: '/',
  142. },
  143. chainWebpack: webpackPlugin,
  144. } as IConfig;