config.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. import defaultSettings from './defaultSettings'; // https://umijs.org/config/
  2. import slash from 'slash2';
  3. import webpackPlugin from './plugin.config';
  4. const { pwa, primaryColor } = defaultSettings; // preview.pro.ant.design only do not use in your production ;
  5. // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  6. const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
  7. const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
  8. const plugins = [
  9. [
  10. 'umi-plugin-react',
  11. {
  12. antd: true,
  13. dva: {
  14. hmr: true,
  15. },
  16. locale: {
  17. // default false
  18. enable: true,
  19. // default zh-CN
  20. default: 'zh-CN',
  21. // default true, when it is true, will use `navigator.language` overwrite default
  22. baseNavigator: true,
  23. },
  24. // dynamicImport: {
  25. // loadingComponent: './components/PageLoading/index',
  26. // webpackChunkName: true,
  27. // level: 3,
  28. // },
  29. pwa: pwa
  30. ? {
  31. workboxPluginMode: 'InjectManifest',
  32. workboxOptions: {
  33. importWorkboxFrom: 'local',
  34. },
  35. }
  36. : false,
  37. // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
  38. // dll features https://webpack.js.org/plugins/dll-plugin/
  39. // dll: {
  40. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  41. // exclude: ['@babel/runtime', 'netlify-lambda'],
  42. // },
  43. hd: false,
  44. },
  45. ],
  46. [
  47. 'umi-plugin-pro-block',
  48. {
  49. moveMock: false,
  50. moveService: false,
  51. modifyRequest: true,
  52. autoAddMenu: true,
  53. },
  54. ],
  55. ]; // 针对 preview.pro.ant.design 的 GA 统计代码
  56. if (isAntDesignProPreview) {
  57. plugins.push([
  58. 'umi-plugin-ga',
  59. {
  60. code: 'UA-72788897-6',
  61. },
  62. ]);
  63. }
  64. export default {
  65. plugins,
  66. block: {
  67. // 国内用户可以使用码云
  68. defaultGitUrl: 'https://gitee.com/ant-design/pro-blocks', // defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  69. },
  70. history: 'browser',
  71. hash: false,
  72. targets: {
  73. ie: 11,
  74. },
  75. devtool: isAntDesignProPreview ? 'source-map' : false,
  76. // umi routes: https://umijs.org/zh/guide/router.html
  77. routes: [
  78. {
  79. path: '/',
  80. component: '../layouts/BlankLayout',
  81. routes: [
  82. {
  83. path: '/user',
  84. component: '../layouts/UserLayout',
  85. routes: [
  86. {
  87. path: '/user',
  88. redirect: '/user/login',
  89. },
  90. {
  91. name: 'login',
  92. icon: 'smile',
  93. path: '/user/login',
  94. component: './user/login',
  95. },
  96. {
  97. name: 'register-result',
  98. icon: 'smile',
  99. path: '/user/register-result',
  100. component: './user/register-result',
  101. },
  102. {
  103. name: 'register',
  104. icon: 'smile',
  105. path: '/user/register',
  106. component: './user/register',
  107. },
  108. {
  109. component: '404',
  110. },
  111. ],
  112. },
  113. {
  114. path: '/',
  115. component: '../layouts/BasicLayout',
  116. Routes: ['src/pages/Authorized'],
  117. authority: ['admin', 'user'],
  118. routes: [
  119. {
  120. path: '/dashboard',
  121. name: 'dashboard',
  122. icon: 'dashboard',
  123. routes: [
  124. {
  125. name: 'analysis',
  126. icon: 'smile',
  127. path: '/dashboard/analysis',
  128. component: './dashboard/analysis',
  129. },
  130. {
  131. name: 'monitor',
  132. icon: 'smile',
  133. path: '/dashboard/monitor',
  134. component: './dashboard/monitor',
  135. },
  136. {
  137. name: 'workplace',
  138. icon: 'smile',
  139. path: '/dashboard/workplace',
  140. component: './dashboard/workplace',
  141. },
  142. ],
  143. },
  144. {
  145. path: '/form',
  146. icon: 'form',
  147. name: 'form',
  148. routes: [
  149. {
  150. name: 'basic-form',
  151. icon: 'smile',
  152. path: '/form/basic-form',
  153. component: './form/basic-form',
  154. },
  155. {
  156. name: 'step-form',
  157. icon: 'smile',
  158. path: '/form/step-form',
  159. component: './form/step-form',
  160. },
  161. {
  162. name: 'advanced-form',
  163. icon: 'smile',
  164. path: '/form/advanced-form',
  165. component: './form/advanced-form',
  166. },
  167. ],
  168. },
  169. {
  170. path: '/list',
  171. icon: 'table',
  172. name: 'list',
  173. routes: [
  174. {
  175. path: '/list/search',
  176. name: 'search-list',
  177. component: './list/search',
  178. routes: [
  179. {
  180. path: '/list/search',
  181. redirect: '/list/search/articles',
  182. },
  183. {
  184. name: 'articles',
  185. icon: 'smile',
  186. path: '/list/search/articles',
  187. component: './list/search/articles',
  188. },
  189. {
  190. name: 'projects',
  191. icon: 'smile',
  192. path: '/list/search/projects',
  193. component: './list/search/projects',
  194. },
  195. {
  196. name: 'applications',
  197. icon: 'smile',
  198. path: '/list/search/applications',
  199. component: './list/search/applications',
  200. },
  201. ],
  202. },
  203. {
  204. name: 'table-list',
  205. icon: 'smile',
  206. path: '/list/table-list',
  207. component: './list/table-list',
  208. },
  209. {
  210. name: 'basic-list',
  211. icon: 'smile',
  212. path: '/list/basic-list',
  213. component: './list/basic-list',
  214. },
  215. {
  216. name: 'card-list',
  217. icon: 'smile',
  218. path: '/list/card-list',
  219. component: './list/card-list',
  220. },
  221. ],
  222. },
  223. {
  224. path: '/profile',
  225. name: 'profile',
  226. icon: 'profile',
  227. routes: [
  228. {
  229. name: 'basic',
  230. icon: 'smile',
  231. path: '/profile/basic',
  232. component: './profile/basic',
  233. },
  234. {
  235. name: 'advanced',
  236. icon: 'smile',
  237. path: '/profile/advanced',
  238. component: './profile/advanced',
  239. },
  240. ],
  241. },
  242. {
  243. name: 'result',
  244. icon: 'check-circle-o',
  245. path: '/result',
  246. routes: [
  247. {
  248. name: 'success',
  249. icon: 'smile',
  250. path: '/result/success',
  251. component: './result/success',
  252. },
  253. ],
  254. },
  255. {
  256. name: 'exception',
  257. icon: 'warning',
  258. path: '/exception',
  259. routes: [],
  260. },
  261. {
  262. name: 'account',
  263. icon: 'user',
  264. path: '/account',
  265. routes: [],
  266. },
  267. {
  268. name: 'editor',
  269. icon: 'highlight',
  270. path: '/editor',
  271. routes: [],
  272. },
  273. {
  274. path: '/',
  275. redirect: '/dashboard/analysis',
  276. authority: ['admin', 'user'],
  277. },
  278. {
  279. component: '404',
  280. },
  281. ],
  282. },
  283. ],
  284. },
  285. ],
  286. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  287. theme: {
  288. 'primary-color': primaryColor,
  289. },
  290. define: {
  291. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  292. 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 专用环境变量,请不要在你的项目中使用它。
  293. },
  294. ignoreMomentLocale: true,
  295. lessLoaderOptions: {
  296. javascriptEnabled: true,
  297. },
  298. disableRedirectHoist: true,
  299. cssLoaderOptions: {
  300. modules: true,
  301. getLocalIdent: (context, _, localName) => {
  302. if (
  303. context.resourcePath.includes('node_modules') ||
  304. context.resourcePath.includes('ant.design.pro.less') ||
  305. context.resourcePath.includes('global.less')
  306. ) {
  307. return localName;
  308. }
  309. const match = context.resourcePath.match(/src(.*)/);
  310. if (match && match[1]) {
  311. const antdProPath = match[1].replace('.less', '');
  312. const arr = slash(antdProPath)
  313. .split('/')
  314. .map(a => a.replace(/([A-Z])/g, '-$1'))
  315. .map(a => a.toLowerCase());
  316. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  317. }
  318. return localName;
  319. },
  320. },
  321. manifest: {
  322. basePath: '/',
  323. },
  324. chainWebpack: webpackPlugin,
  325. /*
  326. proxy: {
  327. '/server/api/': {
  328. target: 'https://preview.pro.ant.design/',
  329. changeOrigin: true,
  330. pathRewrite: { '^/server': '' },
  331. },
  332. },
  333. */
  334. treeShaking: true,
  335. minimizer: 'terserjs',
  336. };