config.js 4.2 KB

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