config.ts 4.4 KB

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