config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // judge add ga
  38. if (process.env.APP_TYPE === 'site') {
  39. plugins.push([
  40. 'umi-plugin-ga',
  41. {
  42. code: 'UA-72788897-6',
  43. },
  44. ]);
  45. }
  46. export default {
  47. // add for transfer to umi
  48. plugins,
  49. targets: {
  50. ie: 11,
  51. },
  52. define: {
  53. APP_TYPE: process.env.APP_TYPE || '',
  54. },
  55. // 路由配置
  56. routes: pageRoutes,
  57. // Theme for antd
  58. // https://ant.design/docs/react/customize-theme-cn
  59. theme: {
  60. 'primary-color': defaultSettings.primaryColor,
  61. },
  62. externals: {
  63. '@antv/data-set': 'DataSet',
  64. },
  65. // proxy: {
  66. // '/server/api/': {
  67. // target: 'https://preview.pro.ant.design/',
  68. // changeOrigin: true,
  69. // pathRewrite: { '^/server': '' },
  70. // },
  71. // },
  72. ignoreMomentLocale: true,
  73. lessLoaderOptions: {
  74. javascriptEnabled: true,
  75. },
  76. disableRedirectHoist: true,
  77. cssLoaderOptions: {
  78. modules: true,
  79. getLocalIdent: (context, localIdentName, localName) => {
  80. if (
  81. context.resourcePath.includes('node_modules') ||
  82. context.resourcePath.includes('ant.design.pro.less') ||
  83. context.resourcePath.includes('global.less')
  84. ) {
  85. return localName;
  86. }
  87. const match = context.resourcePath.match(/src(.*)/);
  88. if (match && match[1]) {
  89. const antdProPath = match[1].replace('.less', '');
  90. const arr = antdProPath
  91. .split('/')
  92. .map(a => a.replace(/([A-Z])/g, '-$1'))
  93. .map(a => a.toLowerCase());
  94. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  95. }
  96. return localName;
  97. },
  98. },
  99. manifest: {
  100. basePath: '/',
  101. },
  102. chainWebpack: webpackPlugin,
  103. };