config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // https://umijs.org/config/
  2. import os from 'os';
  3. import pageRoutes from './router.config';
  4. import webpackPlugin from './plugin.config';
  5. import defaultSettings from '../src/defaultSettings';
  6. import slash from 'slash2';
  7. const plugins = [
  8. [
  9. 'umi-plugin-react',
  10. {
  11. antd: true,
  12. dva: {
  13. hmr: true,
  14. },
  15. locale: {
  16. enable: true, // default false
  17. default: 'zh-CN', // default zh-CN
  18. baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
  19. },
  20. dynamicImport: {
  21. loadingComponent: './components/PageLoading/index',
  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. targets: {
  58. ie: 11,
  59. },
  60. // 路由配置
  61. routes: pageRoutes,
  62. // Theme for antd
  63. // https://ant.design/docs/react/customize-theme-cn
  64. theme: {
  65. 'primary-color': defaultSettings.primaryColor,
  66. },
  67. externals: {
  68. '@antv/data-set': 'DataSet',
  69. },
  70. // proxy: {
  71. // '/server/api/': {
  72. // target: 'https://preview.pro.ant.design/',
  73. // changeOrigin: true,
  74. // pathRewrite: { '^/server': '' },
  75. // },
  76. // },
  77. ignoreMomentLocale: true,
  78. lessLoaderOptions: {
  79. javascriptEnabled: true,
  80. },
  81. disableRedirectHoist: true,
  82. cssLoaderOptions: {
  83. modules: true,
  84. getLocalIdent: (context, localIdentName, localName) => {
  85. if (
  86. context.resourcePath.includes('node_modules') ||
  87. context.resourcePath.includes('ant.design.pro.less') ||
  88. context.resourcePath.includes('global.less')
  89. ) {
  90. return localName;
  91. }
  92. const match = context.resourcePath.match(/src(.*)/);
  93. if (match && match[1]) {
  94. const antdProPath = match[1].replace('.less', '');
  95. const arr = slash(antdProPath)
  96. .split('/')
  97. .map(a => a.replace(/([A-Z])/g, '-$1'))
  98. .map(a => a.toLowerCase());
  99. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  100. }
  101. return localName;
  102. },
  103. },
  104. manifest: {
  105. basePath: '/',
  106. },
  107. chainWebpack: webpackPlugin,
  108. };