config.js 3.1 KB

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