// https://umijs.org/config/ import os from 'os'; import slash from 'slash2'; import pageRoutes from './router.config'; import webpackPlugin from './plugin.config'; import defaultSettings from '../src/defaultSettings'; // import CompressionPlugin from 'compression-webpack-plugin'; const { pwa, primaryColor } = defaultSettings; const { NODE_ENV, APP_TYPE, TEST } = process.env; const plugins = [ [ 'umi-plugin-react', { antd: true, dva: { hmr: true, }, locale: { enable: false, // default false default: 'zh-CN', // default zh-CN baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default }, dynamicImport: { loadingComponent: './components/PageLoading/index', webpackChunkName: true, level: 3, }, pwa: pwa ? { workboxPluginMode: 'InjectManifest', workboxOptions: { importWorkboxFrom: 'local', }, } : {}, ...(!TEST && os.platform() === 'darwin' ? { dll: { include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'], exclude: ['@babel/runtime'], }, hardSource: false, } : {}), }, ], // [ // 'compression-webpack-plugin' // ] ]; // 针对 preview.pro.ant.design 的 GA 统计代码 // 业务上不需要这个 if (APP_TYPE === 'site') { plugins.push([ 'umi-plugin-ga', { code: 'UA-72788897-6', }, ]); } export default { hash: true, // add for transfer to umi plugins, base: '/bom/', publicPath: NODE_ENV == 'development' ? '/' : '/bom/', // base: '/', // publicPath: '/', history: 'hash', define: { APP_TYPE: APP_TYPE || '', // API_HOST: 'http://oraysmart.com:8888' }, treeShaking: true, targets: { ie: 11, }, // 路由配置 routes: pageRoutes, // Theme for antd // https://ant.design/docs/react/customize-theme-cn theme: { 'primary-color': primaryColor, }, // externals: { // bizcharts: 'BizCharts', // }, externals: { // 'react': 'window.React', // 'react-dom': 'window.ReactDOM', // '@antv/g2': 'window.G2', // 'lodash': 'window.lodash', // 'antd/lib/index': 'window.antd', // 'antd/es/index': 'window.antd', // 'antd': 'window.antd', // 'moment': 'window.moment', // 'moment/moment': 'window.moment', // '@antv/data-set': 'DataSet', }, // scripts: [ // 'https://gw.alipayobjects.com/os/lib/react/16.13.1/umd/react.production.min.js', // 'https://gw.alipayobjects.com/os/lib/react-dom/16.13.1/umd/react-dom.production.min.js', // 'https://cdnjs.cloudflare.com/ajax/libs/antv-g2/3.5.19/g2.min.js', // ], ignoreMomentLocale: true, lessLoaderOptions: { javascriptEnabled: true, }, disableRedirectHoist: true, cssLoaderOptions: { modules: true, getLocalIdent: (context, localIdentName, localName) => { if ( context.resourcePath.includes('node_modules') || context.resourcePath.includes('ant.design.pro.less') || context.resourcePath.includes('global.less') ) { return localName; } const match = context.resourcePath.match(/src(.*)/); if (match && match[1]) { const antdProPath = match[1].replace('.less', ''); const arr = slash(antdProPath) .split('/') .map(a => a.replace(/([A-Z])/g, '-$1')) .map(a => a.toLowerCase()); return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-'); } return localName; }, }, manifest: { basePath: '/', }, chainWebpack: webpackPlugin, proxy: { '/api': { target: 'http://192.168.20.152:8888/', // target: 'http://47.96.12.136:8896/', // target: 'http://oraysmart.com:8889/', // target: 'http://oraysmart.com:8888/api', // changeOrigin: true, // pathRewrite: { '^/api': '' }, }, '/config': { target: 'http://127.0.0.1:8888/', //target: 'http://oraysmart.com:8888/', }, '/device': { target: 'http://127.0.0.1:8888/', //target: 'http://oraysmart.com:8888/', }, '/fs': { target: 'http://oraysmart.com:8888/', // target: 'http://oraysmart.com:8888/', }, '/setting': { target: 'http://127.0.0.1:8888/', //target: 'http://oraysmart.com:8888/', }, '/v1': { target: 'https://water-service.oss-cn-hangzhou.aliyuncs.com/', changeOrigin: true, ws: true, pathRewrite: { '^/v1': '', }, }, '/v2': { target: 'https://tz-server-res.oss-cn-beijing.aliyuncs.com/', changeOrigin: true, ws: true, pathRewrite: { '^/v2': '', }, }, }, };