config.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. block: {
  90. defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  91. },
  92. treeShaking: true,
  93. targets: {
  94. ie: 11,
  95. },
  96. devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
  97. // 路由配置
  98. routes: [
  99. {
  100. path: '/',
  101. component: '../layouts/BasicLayout',
  102. Routes: ['src/pages/Authorized'],
  103. authority: ['admin', 'user'],
  104. routes: [
  105. {
  106. path: '/',
  107. name: 'welcome',
  108. icon: 'smile',
  109. component: './Welcome',
  110. },
  111. ],
  112. },
  113. ],
  114. // Theme for antd
  115. // https://ant.design/docs/react/customize-theme-cn
  116. theme: {
  117. 'primary-color': primaryColor,
  118. },
  119. // proxy: {
  120. // '/server/api/': {
  121. // target: 'https://preview.pro.ant.design/',
  122. // changeOrigin: true,
  123. // pathRewrite: { '^/server': '' },
  124. // },
  125. // },
  126. ignoreMomentLocale: true,
  127. lessLoaderOptions: {
  128. javascriptEnabled: true,
  129. },
  130. disableRedirectHoist: true,
  131. cssLoaderOptions: {
  132. modules: true,
  133. getLocalIdent: (
  134. context: {
  135. resourcePath: string;
  136. },
  137. localIdentName: string,
  138. localName: string,
  139. ) => {
  140. if (
  141. context.resourcePath.includes('node_modules') ||
  142. context.resourcePath.includes('ant.design.pro.less') ||
  143. context.resourcePath.includes('global.less')
  144. ) {
  145. return localName;
  146. }
  147. const match = context.resourcePath.match(/src(.*)/);
  148. if (match && match[1]) {
  149. const antdProPath = match[1].replace('.less', '');
  150. const arr = slash(antdProPath)
  151. .split('/')
  152. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  153. .map((a: string) => a.toLowerCase());
  154. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  155. }
  156. return localName;
  157. },
  158. },
  159. manifest: {
  160. basePath: '/',
  161. },
  162. uglifyJSOptions,
  163. chainWebpack: webpackPlugin,
  164. } as IConfig;