config.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. const { APP_TYPE, TEST } = process.env;
  9. const plugins: IPlugin[] = [
  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', 'netlify-lambda'],
  40. },
  41. hardSource: false,
  42. }
  43. : {}),
  44. },
  45. ],
  46. [
  47. 'umi-plugin-pro-block',
  48. {
  49. moveMock: false,
  50. moveService: false,
  51. modifyRequest: true,
  52. autoAddMenu: true,
  53. },
  54. ],
  55. // ...(!process.env.TEST && os.platform() === 'darwin'
  56. // ? {
  57. // dll: {
  58. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  59. // exclude: ['@babel/runtime'],
  60. // },
  61. // hardSource: true,
  62. // }
  63. // : {}),
  64. ];
  65. // 针对 preview.pro.ant.design 的 GA 统计代码
  66. // 业务上不需要这个
  67. if (APP_TYPE === 'site') {
  68. plugins.push([
  69. 'umi-plugin-ga',
  70. {
  71. code: 'UA-72788897-6',
  72. },
  73. ]);
  74. }
  75. export default {
  76. // add for transfer to umi
  77. plugins,
  78. define: {
  79. APP_TYPE: APP_TYPE || '',
  80. },
  81. treeShaking: true,
  82. targets: {
  83. ie: 11,
  84. },
  85. // 路由配置
  86. routes: [
  87. {
  88. path: '/user',
  89. components: ['../layouts/UserLayout'],
  90. routes: [],
  91. },
  92. {
  93. path: '/',
  94. component: '../layouts/BasicLayout',
  95. Routes: ['src/pages/Authorized'],
  96. authority: ['admin', 'user'],
  97. routes: [
  98. // dashboard
  99. {
  100. path: '/',
  101. name: 'welcome',
  102. icon: 'smile',
  103. component: './Welcome',
  104. },
  105. ],
  106. },
  107. ],
  108. // Theme for antd
  109. // https://ant.design/docs/react/customize-theme-cn
  110. theme: {
  111. 'primary-color': primaryColor,
  112. },
  113. // proxy: {
  114. // '/server/api/': {
  115. // target: 'https://preview.pro.ant.design/',
  116. // changeOrigin: true,
  117. // pathRewrite: { '^/server': '' },
  118. // },
  119. // },
  120. ignoreMomentLocale: true,
  121. lessLoaderOptions: {
  122. javascriptEnabled: true,
  123. },
  124. disableRedirectHoist: true,
  125. cssLoaderOptions: {
  126. modules: true,
  127. getLocalIdent: (context, localIdentName, localName) => {
  128. if (
  129. context.resourcePath.includes('node_modules') ||
  130. context.resourcePath.includes('ant.design.pro.less') ||
  131. context.resourcePath.includes('global.less')
  132. ) {
  133. return localName;
  134. }
  135. const match = context.resourcePath.match(/src(.*)/);
  136. if (match && match[1]) {
  137. const antdProPath = match[1].replace('.less', '');
  138. const arr = slash(antdProPath)
  139. .split('/')
  140. .map(a => a.replace(/([A-Z])/g, '-$1'))
  141. .map(a => a.toLowerCase());
  142. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  143. }
  144. return localName;
  145. },
  146. },
  147. manifest: {
  148. basePath: '/',
  149. },
  150. chainWebpack: webpackPlugin,
  151. } as IConfig;