config.js 2.9 KB

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