config.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // https://umijs.org/config/
  2. import os from 'os';
  3. import slash from 'slash2';
  4. import { IPlugin } 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: {
  28. workboxPluginMode: 'InjectManifest',
  29. workboxOptions: {
  30. importWorkboxFrom: 'local',
  31. },
  32. },
  33. },
  34. ],
  35. [
  36. 'umi-plugin-pro-block',
  37. {
  38. moveMock: false,
  39. moveService: false,
  40. modifyRequest: true,
  41. autoAddMenu: true,
  42. },
  43. ],
  44. // ...(!process.env.TEST && os.platform() === 'darwin'
  45. // ? {
  46. // dll: {
  47. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  48. // exclude: ['@babel/runtime'],
  49. // },
  50. // hardSource: true,
  51. // }
  52. // : {}),
  53. ];
  54. // 针对 preview.pro.ant.design 的 GA 统计代码
  55. // 业务上不需要这个
  56. if (APP_TYPE === 'site') {
  57. plugins.push([
  58. 'umi-plugin-ga',
  59. {
  60. code: 'UA-72788897-6',
  61. },
  62. ]);
  63. }
  64. export default {
  65. // add for transfer to umi
  66. plugins,
  67. define: {
  68. APP_TYPE: APP_TYPE || '',
  69. },
  70. treeShaking: true,
  71. targets: {
  72. ie: 11,
  73. },
  74. // 路由配置
  75. routes: [
  76. {
  77. path: '/user',
  78. components: ['../layouts/UserLayout'],
  79. routes: [],
  80. },
  81. {
  82. path: '/',
  83. component: '../layouts/BasicLayout',
  84. Routes: ['src/pages/Authorized'],
  85. authority: ['admin', 'user'],
  86. routes: [
  87. // dashboard
  88. {
  89. path: '/',
  90. name: 'welcome',
  91. icon: 'smile',
  92. component: './Welcome',
  93. },
  94. ],
  95. },
  96. ],
  97. // Theme for antd
  98. // https://ant.design/docs/react/customize-theme-cn
  99. theme: {
  100. 'primary-color': primaryColor,
  101. },
  102. externals: {
  103. '@antv/data-set': 'DataSet',
  104. bizcharts: 'BizCharts',
  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. };