config.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. ]; // 针对 preview.pro.ant.design 的 GA 统计代码
  61. // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  62. if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
  63. plugins.push([
  64. 'umi-plugin-ga',
  65. {
  66. code: 'UA-72788897-6',
  67. },
  68. ]);
  69. }
  70. const uglifyJSOptions =
  71. NODE_ENV === 'production'
  72. ? {
  73. uglifyOptions: {
  74. // remove console.* except console.error
  75. compress: {
  76. drop_console: true,
  77. pure_funcs: ['console.error'],
  78. },
  79. },
  80. }
  81. : {};
  82. export default {
  83. // add for transfer to umi
  84. plugins,
  85. define: {
  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. treeShaking: true,
  90. targets: {
  91. ie: 11,
  92. },
  93. devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
  94. // 路由配置
  95. routes: [
  96. {
  97. path: '/',
  98. component: '../layouts/BasicLayout',
  99. Routes: ['src/pages/Authorized'],
  100. authority: ['admin', 'user'],
  101. routes: [
  102. {
  103. path: '/',
  104. name: 'welcome',
  105. icon: 'smile',
  106. component: './Welcome',
  107. },
  108. ],
  109. },
  110. ],
  111. // Theme for antd
  112. // https://ant.design/docs/react/customize-theme-cn
  113. theme: {
  114. 'primary-color': primaryColor,
  115. },
  116. // proxy: {
  117. // '/server/api/': {
  118. // target: 'https://preview.pro.ant.design/',
  119. // changeOrigin: true,
  120. // pathRewrite: { '^/server': '' },
  121. // },
  122. // },
  123. ignoreMomentLocale: true,
  124. lessLoaderOptions: {
  125. javascriptEnabled: true,
  126. },
  127. disableRedirectHoist: true,
  128. cssLoaderOptions: {
  129. modules: true,
  130. getLocalIdent: (
  131. context: {
  132. resourcePath: string;
  133. },
  134. localIdentName: string,
  135. localName: string,
  136. ) => {
  137. if (
  138. context.resourcePath.includes('node_modules') ||
  139. context.resourcePath.includes('ant.design.pro.less') ||
  140. context.resourcePath.includes('global.less')
  141. ) {
  142. return localName;
  143. }
  144. const match = context.resourcePath.match(/src(.*)/);
  145. if (match && match[1]) {
  146. const antdProPath = match[1].replace('.less', '');
  147. const arr = slash(antdProPath)
  148. .split('/')
  149. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  150. .map((a: string) => a.toLowerCase());
  151. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  152. }
  153. return localName;
  154. },
  155. },
  156. manifest: {
  157. basePath: '/',
  158. },
  159. uglifyJSOptions,
  160. chainWebpack: webpackPlugin,
  161. } as IConfig;