config.js 2.8 KB

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