config.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // https://umijs.org/config/
  2. import os from 'os';
  3. import slash from 'slash2';
  4. import { IPlugin, IConfig } from 'umi-types';
  5. import defaultSettings from './defaultSettings';
  6. import webpackPlugin from './plugin.config';
  7. const { pwa, primaryColor } = defaultSettings;
  8. // preview.pro.ant.design only do not use in your production ;
  9. // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  10. const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env;
  11. const plugins: IPlugin[] = [
  12. [
  13. 'umi-plugin-react',
  14. {
  15. antd: true,
  16. dva: {
  17. hmr: true,
  18. },
  19. locale: {
  20. // default false
  21. enable: true,
  22. // default zh-CN
  23. default: 'zh-CN',
  24. // default true, when it is true, will use `navigator.language` overwrite default
  25. baseNavigator: true,
  26. },
  27. dynamicImport: {
  28. loadingComponent: './components/PageLoading/index',
  29. webpackChunkName: true,
  30. level: 3,
  31. },
  32. pwa: pwa
  33. ? {
  34. workboxPluginMode: 'InjectManifest',
  35. workboxOptions: {
  36. importWorkboxFrom: 'local',
  37. },
  38. }
  39. : false,
  40. ...(!TEST && os.platform() === 'darwin'
  41. ? {
  42. dll: {
  43. include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  44. exclude: ['@babel/runtime', 'netlify-lambda'],
  45. },
  46. hardSource: false,
  47. }
  48. : {}),
  49. },
  50. ],
  51. [
  52. 'umi-plugin-pro-block',
  53. {
  54. moveMock: false,
  55. moveService: false,
  56. modifyRequest: true,
  57. autoAddMenu: true,
  58. },
  59. ],
  60. ];
  61. // 针对 preview.pro.ant.design 的 GA 统计代码
  62. // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  63. if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
  64. plugins.push([
  65. 'umi-plugin-ga',
  66. {
  67. code: 'UA-72788897-6',
  68. },
  69. ]);
  70. }
  71. const uglifyJSOptions =
  72. NODE_ENV === 'production'
  73. ? {
  74. uglifyOptions: {
  75. // remove console.* except console.error
  76. compress: {
  77. drop_console: true,
  78. pure_funcs: ['console.error'],
  79. },
  80. },
  81. }
  82. : {};
  83. export default {
  84. // add for transfer to umi
  85. plugins,
  86. define: {
  87. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  88. 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 专用环境变量,请不要在你的项目中使用它。
  89. },
  90. treeShaking: true,
  91. targets: {
  92. ie: 11,
  93. },
  94. devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
  95. // 路由配置
  96. routes: [
  97. {
  98. path: '/',
  99. component: '../layouts/BasicLayout',
  100. Routes: ['src/pages/Authorized'],
  101. authority: ['admin', 'user'],
  102. routes: [
  103. {
  104. path: '/',
  105. name: 'Analysis',
  106. icon: 'dashboard',
  107. component: './analysis',
  108. },
  109. ],
  110. },
  111. ],
  112. // Theme for antd
  113. // https://ant.design/docs/react/customize-theme-cn
  114. theme: {
  115. 'primary-color': primaryColor,
  116. },
  117. // proxy: {
  118. // '/server/api/': {
  119. // target: 'https://preview.pro.ant.design/',
  120. // changeOrigin: true,
  121. // pathRewrite: { '^/server': '' },
  122. // },
  123. // },
  124. ignoreMomentLocale: true,
  125. lessLoaderOptions: {
  126. javascriptEnabled: true,
  127. },
  128. disableRedirectHoist: true,
  129. cssLoaderOptions: {
  130. modules: true,
  131. getLocalIdent: (
  132. context: {
  133. resourcePath: string;
  134. },
  135. localIdentName: string,
  136. localName: string,
  137. ) => {
  138. if (
  139. context.resourcePath.includes('node_modules') ||
  140. context.resourcePath.includes('ant.design.pro.less') ||
  141. context.resourcePath.includes('global.less')
  142. ) {
  143. return localName;
  144. }
  145. const match = context.resourcePath.match(/src(.*)/);
  146. if (match && match[1]) {
  147. const antdProPath = match[1].replace('.less', '');
  148. const arr = slash(antdProPath)
  149. .split('/')
  150. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  151. .map((a: string) => a.toLowerCase());
  152. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  153. }
  154. return localName;
  155. },
  156. },
  157. manifest: {
  158. basePath: '/',
  159. },
  160. uglifyJSOptions,
  161. chainWebpack: webpackPlugin,
  162. } as IConfig;