config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // https://umijs.org/config/
  2. import os from 'os';
  3. import webpackPlugin from './plugin.config';
  4. import defaultSettings from '../src/defaultSettings';
  5. import slash from 'slash2';
  6. const { pwa, primaryColor } = defaultSettings;
  7. const { NODE_ENV, APP_TYPE, TEST } = process.env;
  8. const plugins = [
  9. [
  10. 'umi-plugin-react',
  11. {
  12. antd: true,
  13. dva: {
  14. hmr: true,
  15. },
  16. locale: {
  17. enable: true, // default false
  18. default: 'zh-CN', // default zh-CN
  19. baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
  20. },
  21. dynamicImport: {
  22. loadingComponent: './components/PageLoading/index',
  23. webpackChunkName: true,
  24. level: 3,
  25. },
  26. pwa: {
  27. workboxPluginMode: 'InjectManifest',
  28. workboxOptions: {
  29. importWorkboxFrom: 'local',
  30. },
  31. },
  32. },
  33. ],
  34. [
  35. 'umi-plugin-pro-block',
  36. {
  37. moveMock: false,
  38. moveService: false,
  39. modifyRequest: true,
  40. autoAddMenu: true,
  41. },
  42. ],
  43. // ...(!process.env.TEST && os.platform() === 'darwin'
  44. // ? {
  45. // dll: {
  46. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  47. // exclude: ['@babel/runtime'],
  48. // },
  49. // hardSource: true,
  50. // }
  51. // : {}),
  52. ];
  53. // 针对 preview.pro.ant.design 的 GA 统计代码
  54. // 业务上不需要这个
  55. if (APP_TYPE === 'site') {
  56. plugins.push([
  57. 'umi-plugin-ga',
  58. {
  59. code: 'UA-72788897-6',
  60. },
  61. ]);
  62. }
  63. export default {
  64. // add for transfer to umi
  65. plugins,
  66. define: {
  67. APP_TYPE: APP_TYPE || '',
  68. },
  69. treeShaking: true,
  70. targets: {
  71. ie: 11,
  72. },
  73. // 路由配置
  74. routes: [
  75. {
  76. path: '/user',
  77. components: ['../layouts/UserLayout'],
  78. routes: [],
  79. },
  80. {
  81. path: '/',
  82. component: '../layouts/BasicLayout',
  83. Routes: ['src/pages/Authorized'],
  84. authority: ['admin', 'user'],
  85. routes: [
  86. // dashboard
  87. {
  88. path: '/',
  89. name: 'welcome',
  90. icon: 'smile',
  91. component: './Welcome',
  92. },
  93. ],
  94. },
  95. ],
  96. // Theme for antd
  97. // https://ant.design/docs/react/customize-theme-cn
  98. theme: {
  99. 'primary-color': primaryColor,
  100. },
  101. externals: {
  102. '@antv/data-set': 'DataSet',
  103. bizcharts: 'BizCharts',
  104. },
  105. // proxy: {
  106. // '/server/api/': {
  107. // target: 'https://preview.pro.ant.design/',
  108. // changeOrigin: true,
  109. // pathRewrite: { '^/server': '' },
  110. // },
  111. // },
  112. ignoreMomentLocale: true,
  113. lessLoaderOptions: {
  114. javascriptEnabled: true,
  115. },
  116. disableRedirectHoist: true,
  117. cssLoaderOptions: {
  118. modules: true,
  119. getLocalIdent: (context, localIdentName, localName) => {
  120. if (
  121. context.resourcePath.includes('node_modules') ||
  122. context.resourcePath.includes('ant.design.pro.less') ||
  123. context.resourcePath.includes('global.less')
  124. ) {
  125. return localName;
  126. }
  127. const match = context.resourcePath.match(/src(.*)/);
  128. if (match && match[1]) {
  129. const antdProPath = match[1].replace('.less', '');
  130. const arr = slash(antdProPath)
  131. .split('/')
  132. .map(a => a.replace(/([A-Z])/g, '-$1'))
  133. .map(a => a.toLowerCase());
  134. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  135. }
  136. return localName;
  137. },
  138. },
  139. manifest: {
  140. basePath: '/',
  141. },
  142. chainWebpack: webpackPlugin,
  143. };