config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // https://umijs.org/config/
  2. import os from 'os';
  3. import slash from 'slash2';
  4. import pageRoutes from './router.config';
  5. import webpackPlugin from './plugin.config';
  6. import defaultSettings from '../src/defaultSettings';
  7. // import CompressionPlugin from 'compression-webpack-plugin';
  8. const { pwa, primaryColor } = defaultSettings;
  9. const { NODE_ENV, APP_TYPE, TEST } = process.env;
  10. const plugins = [
  11. [
  12. 'umi-plugin-react',
  13. {
  14. antd: true,
  15. dva: {
  16. hmr: true,
  17. },
  18. locale: {
  19. enable: false, // default false
  20. default: 'zh-CN', // default zh-CN
  21. baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
  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. : {},
  36. ...(!TEST && os.platform() === 'darwin'
  37. ? {
  38. dll: {
  39. include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  40. exclude: ['@babel/runtime'],
  41. },
  42. hardSource: false,
  43. }
  44. : {}),
  45. },
  46. ],
  47. // [
  48. // 'compression-webpack-plugin'
  49. // ]
  50. ];
  51. // 针对 preview.pro.ant.design 的 GA 统计代码
  52. // 业务上不需要这个
  53. if (APP_TYPE === 'site') {
  54. plugins.push([
  55. 'umi-plugin-ga',
  56. {
  57. code: 'UA-72788897-6',
  58. },
  59. ]);
  60. }
  61. export default {
  62. // add for transfer to umi
  63. plugins,
  64. base: '/bom/',
  65. publicPath: NODE_ENV == 'development' ? '/' : '/bom/',
  66. // base: '/',
  67. // publicPath: '/',
  68. history: 'hash',
  69. define: {
  70. APP_TYPE: APP_TYPE || '',
  71. // API_HOST: 'http://oraysmart.com:8888'
  72. },
  73. treeShaking: true,
  74. targets: {
  75. ie: 11,
  76. },
  77. // 路由配置
  78. routes: pageRoutes,
  79. // Theme for antd
  80. // https://ant.design/docs/react/customize-theme-cn
  81. theme: {
  82. 'primary-color': primaryColor,
  83. },
  84. // externals: {
  85. // bizcharts: 'BizCharts',
  86. // },
  87. externals: {
  88. // 'react': 'window.React',
  89. // 'react-dom': 'window.ReactDOM',
  90. // '@antv/g2': 'window.G2',
  91. // 'lodash': 'window.lodash',
  92. // 'antd/lib/index': 'window.antd',
  93. // 'antd/es/index': 'window.antd',
  94. // 'antd': 'window.antd',
  95. // 'moment': 'window.moment',
  96. // 'moment/moment': 'window.moment',
  97. // '@antv/data-set': 'DataSet',
  98. },
  99. // scripts: [
  100. // 'https://gw.alipayobjects.com/os/lib/react/16.13.1/umd/react.production.min.js',
  101. // 'https://gw.alipayobjects.com/os/lib/react-dom/16.13.1/umd/react-dom.production.min.js',
  102. // 'https://cdnjs.cloudflare.com/ajax/libs/antv-g2/3.5.19/g2.min.js',
  103. // ],
  104. ignoreMomentLocale: true,
  105. lessLoaderOptions: {
  106. javascriptEnabled: true,
  107. },
  108. disableRedirectHoist: true,
  109. cssLoaderOptions: {
  110. modules: true,
  111. getLocalIdent: (context, localIdentName, localName) => {
  112. if (
  113. context.resourcePath.includes('node_modules') ||
  114. context.resourcePath.includes('ant.design.pro.less') ||
  115. context.resourcePath.includes('global.less')
  116. ) {
  117. return localName;
  118. }
  119. const match = context.resourcePath.match(/src(.*)/);
  120. if (match && match[1]) {
  121. const antdProPath = match[1].replace('.less', '');
  122. const arr = slash(antdProPath)
  123. .split('/')
  124. .map(a => a.replace(/([A-Z])/g, '-$1'))
  125. .map(a => a.toLowerCase());
  126. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  127. }
  128. return localName;
  129. },
  130. },
  131. manifest: {
  132. basePath: '/',
  133. },
  134. chainWebpack: webpackPlugin,
  135. proxy: {
  136. '/api': {
  137. target: 'http://47.96.12.136:8896/',
  138. // target: 'http://oraysmart.com:8889/',
  139. // target: 'http://oraysmart.com:8888/api',
  140. // changeOrigin: true,
  141. // pathRewrite: { '^/api': '' },
  142. },
  143. '/config': {
  144. target: 'http://127.0.0.1:8888/',
  145. //target: 'http://oraysmart.com:8888/',
  146. },
  147. '/device': {
  148. target: 'http://127.0.0.1:8888/',
  149. //target: 'http://oraysmart.com:8888/',
  150. },
  151. '/fs': {
  152. target: 'http://oraysmart.com:8888/',
  153. // target: 'http://oraysmart.com:8888/',
  154. },
  155. '/setting': {
  156. target: 'http://127.0.0.1:8888/',
  157. //target: 'http://oraysmart.com:8888/',
  158. },
  159. '/v1': {
  160. target: 'https://water-service.oss-cn-hangzhou.aliyuncs.com/',
  161. changeOrigin: true,
  162. ws: true,
  163. pathRewrite: {
  164. '^/v1': '',
  165. },
  166. },
  167. '/v2': {
  168. target: 'https://tz-server-res.oss-cn-beijing.aliyuncs.com/',
  169. changeOrigin: true,
  170. ws: true,
  171. pathRewrite: {
  172. '^/v2': '',
  173. },
  174. },
  175. },
  176. };