config.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { IConfig, IPlugin } from 'umi-types';
  2. import defaultSettings from './defaultSettings'; // https://umijs.org/config/
  3. import slash from 'slash2';
  4. import themePluginConfig from './themePluginConfig';
  5. import proxy from './proxy';
  6. import webpackPlugin from './plugin.config';
  7. import { routes } from './routes';
  8. const { pwa } = defaultSettings;
  9. // preview.pro.ant.design only do not use in your production ;
  10. // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  11. const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV } = process.env;
  12. const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
  13. const plugins: IPlugin[] = [
  14. [
  15. 'umi-plugin-react',
  16. {
  17. antd: true,
  18. dva: {
  19. hmr: true,
  20. },
  21. locale: {
  22. // default false
  23. enable: true,
  24. // default zh-CN
  25. default: 'zh-CN',
  26. // default true, when it is true, will use `navigator.language` overwrite default
  27. baseNavigator: true,
  28. },
  29. dynamicImport: {
  30. loadingComponent: './components/PageLoading/index',
  31. webpackChunkName: true,
  32. level: 3,
  33. },
  34. pwa: pwa
  35. ? {
  36. workboxPluginMode: 'InjectManifest',
  37. workboxOptions: {
  38. importWorkboxFrom: 'local',
  39. },
  40. }
  41. : false, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
  42. // dll features https://webpack.js.org/plugins/dll-plugin/
  43. // dll: {
  44. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  45. // exclude: ['@babel/runtime', 'netlify-lambda'],
  46. // },
  47. },
  48. ],
  49. [
  50. 'umi-plugin-pro-block',
  51. {
  52. moveMock: false,
  53. moveService: false,
  54. modifyRequest: true,
  55. autoAddMenu: true,
  56. },
  57. ],
  58. ];
  59. if (isAntDesignProPreview) {
  60. // 针对 preview.pro.ant.design 的 GA 统计代码
  61. plugins.push([
  62. 'umi-plugin-ga',
  63. {
  64. code: 'UA-72788897-6',
  65. },
  66. ]);
  67. plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
  68. }
  69. export default {
  70. plugins,
  71. hash: true,
  72. targets: {
  73. ie: 11,
  74. },
  75. history: 'hash',
  76. // base: './',
  77. // publicPath: "./",
  78. // umi routes: https://umijs.org/zh/guide/router.html
  79. routes: routes,
  80. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  81. theme: {
  82. // ...darkTheme,
  83. },
  84. define: {
  85. REACT_APP_ENV: REACT_APP_ENV || false,
  86. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  87. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  88. },
  89. ignoreMomentLocale: true,
  90. lessLoaderOptions: {
  91. javascriptEnabled: true,
  92. },
  93. disableRedirectHoist: true,
  94. cssLoaderOptions: {
  95. modules: true,
  96. getLocalIdent: (
  97. context: {
  98. resourcePath: string;
  99. },
  100. _: string,
  101. localName: string,
  102. ) => {
  103. if (
  104. context.resourcePath.includes('node_modules') ||
  105. context.resourcePath.includes('ant.design.pro.less') ||
  106. context.resourcePath.includes('global.less')
  107. ) {
  108. return localName;
  109. }
  110. const match = context.resourcePath.match(/src(.*)/);
  111. if (match && match[1]) {
  112. const antdProPath = match[1].replace('.less', '');
  113. const arr = slash(antdProPath)
  114. .split('/')
  115. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  116. .map((a: string) => a.toLowerCase());
  117. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  118. }
  119. return localName;
  120. },
  121. },
  122. manifest: {
  123. basePath: '/',
  124. },
  125. proxy: proxy[REACT_APP_ENV || 'dev'],
  126. chainWebpack: webpackPlugin,
  127. // extraBabelPlugins: [
  128. // ['transform-remove-console', { exclude: ['error', 'info'] }]
  129. // ]
  130. // proxy: {
  131. // '/jetlinks': {
  132. // // target: 'http://192.168.3.89:8848/',
  133. // target: 'http://2.jetlinks.org:9010/',
  134. // changeOrigin: true,
  135. // pathRewrite: { '^/jetlinks': '' },
  136. // },
  137. // },
  138. } as IConfig;