config.js 2.6 KB

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