config.js 4.0 KB

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