config.js 3.3 KB

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