config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import defaultSettings from './defaultSettings'; // https://umijs.org/config/
  2. import slash from 'slash2';
  3. import themePluginConfig from './themePluginConfig';
  4. const { pwa } = defaultSettings; // preview.pro.ant.design only do not use in your production ;
  5. // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  6. import { routerConfig } from './routerConfig.js';
  7. const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
  8. const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
  9. const plugins = [
  10. [
  11. 'umi-plugin-react',
  12. {
  13. antd: true,
  14. dva: {
  15. hmr: true,
  16. },
  17. locale: {
  18. enable: true,
  19. default: 'zh-CN',
  20. baseNavigator: true,
  21. },
  22. dynamicImport: {
  23. loadingComponent: './components/PageLoading/index',
  24. webpackChunkName: true,
  25. level: 3,
  26. },
  27. pwa: pwa
  28. ? {
  29. workboxPluginMode: 'InjectManifest',
  30. workboxOptions: {
  31. importWorkboxFrom: 'local',
  32. },
  33. }
  34. : false, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
  35. // dll features https://webpack.js.org/plugins/dll-plugin/
  36. // dll: {
  37. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  38. // exclude: ['@babel/runtime', 'netlify-lambda'],
  39. // },
  40. },
  41. ],
  42. [
  43. 'umi-plugin-pro-block',
  44. {
  45. moveMock: false,
  46. moveService: false,
  47. modifyRequest: true,
  48. autoAddMenu: true,
  49. },
  50. ],
  51. ];
  52. if (isAntDesignProPreview) {
  53. // 针对 preview.pro.ant.design 的 GA 统计代码
  54. plugins.push([
  55. 'umi-plugin-ga',
  56. {
  57. code: 'UA-72788897-6',
  58. },
  59. ]);
  60. plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
  61. }
  62. export default {
  63. plugins,
  64. hash: true,
  65. targets: {
  66. ie: 9,
  67. },
  68. // umi routes: https://umijs.org/zh/guide/router.html
  69. routes: routerConfig,
  70. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  71. theme: {
  72. // ...darkTheme,
  73. 'primary-color': '#ff4d5c',
  74. },
  75. define: {
  76. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  77. 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 专用环境变量,请不要在你的项目中使用它。
  78. },
  79. ignoreMomentLocale: true,
  80. lessLoaderOptions: {
  81. javascriptEnabled: true,
  82. },
  83. disableRedirectHoist: true,
  84. cssLoaderOptions: {
  85. modules: true,
  86. getLocalIdent: (context, _, localName) => {
  87. if (
  88. context.resourcePath.includes('node_modules') ||
  89. context.resourcePath.includes('ant.design.pro.less') ||
  90. context.resourcePath.includes('global.less')
  91. ) {
  92. return localName;
  93. }
  94. const match = context.resourcePath.match(/src(.*)/);
  95. if (match && match[1]) {
  96. const antdProPath = match[1].replace('.less', '');
  97. const arr = slash(antdProPath)
  98. .split('/')
  99. .map(a => a.replace(/([A-Z])/g, '-$1'))
  100. .map(a => a.toLowerCase());
  101. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  102. }
  103. return localName;
  104. },
  105. },
  106. manifest: {
  107. basePath: '/',
  108. },
  109. // chainWebpack: webpackPlugin,
  110. proxy: {
  111. '/api-common': {
  112. target: 'http://api.starbuds.laylib.com',
  113. changeOrigin: true,
  114. //pathRewrite: { '^/server': '' },
  115. },
  116. '/api-agent': {
  117. target: 'http://api.starbuds.laylib.com',
  118. changeOrigin: true,
  119. //pathRewrite: { '^/server': '' },
  120. },
  121. },
  122. treeShaking: true,
  123. mock: {
  124. exclude: [],
  125. },
  126. publicPath: '/'
  127. };