config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. hash: true,
  63. // add for transfer to umi
  64. plugins,
  65. base: '/bom/',
  66. publicPath: NODE_ENV == 'development' ? '/' : '/bom/',
  67. // base: '/',
  68. // publicPath: '/',
  69. history: 'hash',
  70. define: {
  71. APP_TYPE: APP_TYPE || '',
  72. // API_HOST: 'http://oraysmart.com:8888'
  73. },
  74. treeShaking: true,
  75. targets: {
  76. ie: 11,
  77. },
  78. // 路由配置
  79. routes: pageRoutes,
  80. // Theme for antd
  81. // https://ant.design/docs/react/customize-theme-cn
  82. theme: {
  83. 'primary-color': primaryColor,
  84. },
  85. // externals: {
  86. // bizcharts: 'BizCharts',
  87. // },
  88. externals: {
  89. // 'react': 'window.React',
  90. // 'react-dom': 'window.ReactDOM',
  91. // '@antv/g2': 'window.G2',
  92. // 'lodash': 'window.lodash',
  93. // 'antd/lib/index': 'window.antd',
  94. // 'antd/es/index': 'window.antd',
  95. // 'antd': 'window.antd',
  96. // 'moment': 'window.moment',
  97. // 'moment/moment': 'window.moment',
  98. // '@antv/data-set': 'DataSet',
  99. },
  100. // scripts: [
  101. // 'https://gw.alipayobjects.com/os/lib/react/16.13.1/umd/react.production.min.js',
  102. // 'https://gw.alipayobjects.com/os/lib/react-dom/16.13.1/umd/react-dom.production.min.js',
  103. // 'https://cdnjs.cloudflare.com/ajax/libs/antv-g2/3.5.19/g2.min.js',
  104. // ],
  105. ignoreMomentLocale: true,
  106. lessLoaderOptions: {
  107. javascriptEnabled: true,
  108. },
  109. disableRedirectHoist: true,
  110. cssLoaderOptions: {
  111. modules: true,
  112. getLocalIdent: (context, localIdentName, localName) => {
  113. if (
  114. context.resourcePath.includes('node_modules') ||
  115. context.resourcePath.includes('ant.design.pro.less') ||
  116. context.resourcePath.includes('global.less')
  117. ) {
  118. return localName;
  119. }
  120. const match = context.resourcePath.match(/src(.*)/);
  121. if (match && match[1]) {
  122. const antdProPath = match[1].replace('.less', '');
  123. const arr = slash(antdProPath)
  124. .split('/')
  125. .map(a => a.replace(/([A-Z])/g, '-$1'))
  126. .map(a => a.toLowerCase());
  127. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  128. }
  129. return localName;
  130. },
  131. },
  132. manifest: {
  133. basePath: '/',
  134. },
  135. chainWebpack: webpackPlugin,
  136. proxy: {
  137. '/api': {
  138. // target: 'http://192.168.20.152:8888/',
  139. // target: 'http://120.55.44.4:8896/',
  140. target: 'http://47.96.12.136:8896/',
  141. // target: 'http://oraysmart.com:8889/',
  142. // target: 'http://oraysmart.com:8888/api',
  143. // changeOrigin: true,
  144. // pathRewrite: { '^/api': '' },
  145. },
  146. '/config': {
  147. target: 'http://127.0.0.1:8888/',
  148. //target: 'http://oraysmart.com:8888/',
  149. },
  150. '/device': {
  151. target: 'http://127.0.0.1:8888/',
  152. //target: 'http://oraysmart.com:8888/',
  153. },
  154. '/fs': {
  155. target: 'http://oraysmart.com:8888/',
  156. // target: 'http://oraysmart.com:8888/',
  157. },
  158. '/setting': {
  159. target: 'http://127.0.0.1:8888/',
  160. //target: 'http://oraysmart.com:8888/',
  161. },
  162. '/v1': {
  163. target: 'https://water-service.oss-cn-hangzhou.aliyuncs.com/',
  164. changeOrigin: true,
  165. ws: true,
  166. pathRewrite: {
  167. '^/v1': '',
  168. },
  169. },
  170. '/v2': {
  171. target: 'https://tz-server-res.oss-cn-beijing.aliyuncs.com/',
  172. changeOrigin: true,
  173. ws: true,
  174. pathRewrite: {
  175. '^/v2': '',
  176. },
  177. },
  178. },
  179. };