config.js 2.8 KB

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