config.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 darkTheme from '@ant-design/dark-theme';
  6. const { pwa, primaryColor } = defaultSettings;
  7. // 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 } = process.env;
  10. const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
  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, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
  40. // dll features https://webpack.js.org/plugins/dll-plugin/
  41. // dll: {
  42. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  43. // exclude: ['@babel/runtime', 'netlify-lambda'],
  44. // },
  45. },
  46. ],
  47. [
  48. 'umi-plugin-pro-block',
  49. {
  50. moveMock: false,
  51. moveService: false,
  52. modifyRequest: true,
  53. autoAddMenu: true,
  54. },
  55. ],
  56. ];
  57. if (isAntDesignProPreview) {
  58. // 针对 preview.pro.ant.design 的 GA 统计代码
  59. plugins.push([
  60. 'umi-plugin-ga',
  61. {
  62. code: 'UA-72788897-6',
  63. },
  64. ]);
  65. plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
  66. }
  67. if (!TEST) {
  68. plugins.push([
  69. 'umi-plugin-antd-theme',
  70. {
  71. theme: [
  72. {
  73. key: 'dark',
  74. fileName: 'dark.css',
  75. theme: 'dark',
  76. },
  77. {
  78. key: 'dust',
  79. fileName: 'dust.css',
  80. modifyVars: {
  81. '@primary-color': '#F5222D',
  82. },
  83. },
  84. {
  85. key: 'dust',
  86. theme: 'dark',
  87. fileName: 'dark-dust.css',
  88. modifyVars: {
  89. '@primary-color': '#F5222D',
  90. },
  91. },
  92. {
  93. key: 'volcano',
  94. theme: 'dark',
  95. fileName: 'dark-volcano.css',
  96. modifyVars: {
  97. '@primary-color': '#FA541C',
  98. },
  99. },
  100. ],
  101. },
  102. ]);
  103. }
  104. export default {
  105. plugins,
  106. block: {
  107. // 国内用户可以使用码云
  108. // defaultGitUrl: 'https://gitee.com/ant-design/pro-blocks',
  109. defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  110. },
  111. hash: true,
  112. targets: {
  113. ie: 11,
  114. },
  115. devtool: isAntDesignProPreview ? 'source-map' : false,
  116. // umi routes: https://umijs.org/zh/guide/router.html
  117. routes: [
  118. {
  119. path: '/user',
  120. component: '../layouts/UserLayout',
  121. routes: [
  122. {
  123. name: 'login',
  124. path: '/user/login',
  125. component: './user/login',
  126. },
  127. ],
  128. },
  129. {
  130. path: '/',
  131. component: '../layouts/SecurityLayout',
  132. routes: [
  133. {
  134. path: '/',
  135. component: '../layouts/BasicLayout',
  136. authority: ['admin', 'user'],
  137. routes: [
  138. {
  139. path: '/',
  140. redirect: '/welcome',
  141. },
  142. {
  143. path: '/welcome',
  144. name: 'welcome',
  145. icon: 'smile',
  146. component: './Welcome',
  147. },
  148. {
  149. path: '/admin',
  150. name: 'admin',
  151. icon: 'crown',
  152. component: './Admin',
  153. authority: ['admin'],
  154. },
  155. {
  156. component: './404',
  157. },
  158. ],
  159. },
  160. {
  161. component: './404',
  162. },
  163. ],
  164. },
  165. {
  166. component: './404',
  167. },
  168. ],
  169. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  170. theme: {
  171. // ...darkTheme,
  172. 'primary-color': primaryColor,
  173. },
  174. define: {
  175. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  176. 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 专用环境变量,请不要在你的项目中使用它。
  177. },
  178. ignoreMomentLocale: true,
  179. lessLoaderOptions: {
  180. javascriptEnabled: true,
  181. },
  182. disableRedirectHoist: true,
  183. cssLoaderOptions: {
  184. modules: true,
  185. getLocalIdent: (
  186. context: {
  187. resourcePath: string;
  188. },
  189. _: string,
  190. localName: string,
  191. ) => {
  192. if (
  193. context.resourcePath.includes('node_modules') ||
  194. context.resourcePath.includes('ant.design.pro.less') ||
  195. context.resourcePath.includes('global.less')
  196. ) {
  197. return localName;
  198. }
  199. const match = context.resourcePath.match(/src(.*)/);
  200. if (match && match[1]) {
  201. const antdProPath = match[1].replace('.less', '');
  202. const arr = slash(antdProPath)
  203. .split('/')
  204. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  205. .map((a: string) => a.toLowerCase());
  206. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  207. }
  208. return localName;
  209. },
  210. },
  211. manifest: {
  212. basePath: '/',
  213. },
  214. // chainWebpack: webpackPlugin,
  215. // proxy: {
  216. // '/server/api/': {
  217. // target: 'https://preview.pro.ant.design/',
  218. // changeOrigin: true,
  219. // pathRewrite: { '^/server': '' },
  220. // },
  221. // },
  222. } as IConfig;