config.js 3.0 KB

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