config.js 2.7 KB
Newer Older
愚道 已提交
1
// https://umijs.org/config/
愚道 已提交
2 3
import os from 'os';
import pageRoutes from './router.config';
陈帅 已提交
4
import webpackPlugin from './plugin.config';
愚道 已提交
5
import defaultSettings from '../src/defaultSettings';
愚道 已提交
6

陈帅 已提交
7 8 9 10 11 12 13 14 15 16
const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      targets: {
        ie: 11,
S
sorrycc 已提交
17
      },
陈帅 已提交
18 19 20 21
      locale: {
        enable: true, // default false
        default: 'zh-CN', // default zh-CN
        baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
陈帅 已提交
22
      },
陈帅 已提交
23 24 25
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
      },
X
xiaoiver 已提交
26 27 28 29 30 31
      pwa: {
        workboxPluginMode: 'InjectManifest',
        workboxOptions: {
          importWorkboxFrom: 'local',
        },
      },
陈帅 已提交
32 33 34 35 36 37 38 39 40 41
      ...(!process.env.TEST && os.platform() === 'darwin'
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
              exclude: ['@babel/runtime'],
            },
            hardSource: true,
          }
        : {}),
    },
愚道 已提交
42
  ],
陈帅 已提交
43 44
];

偏右 已提交
45 46
// 针对 preview.pro.ant.design 的 GA 统计代码
// 业务上不需要这个
陈帅 已提交
47 48 49 50 51 52 53 54 55 56 57 58
if (process.env.APP_TYPE === 'site') {
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // add for transfer to umi
  plugins,
Y
Yu 已提交
59 60 61
  targets: {
    ie: 11,
  },
陈帅 已提交
62
  define: {
陈帅 已提交
63
    APP_TYPE: process.env.APP_TYPE || '',
陈帅 已提交
64
  },
愚道 已提交
65
  // 路由配置
陈帅 已提交
66
  routes: pageRoutes,
A
afc163 已提交
67 68
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
愚道 已提交
69
  theme: {
A
afc163 已提交
70
    'primary-color': defaultSettings.primaryColor,
愚道 已提交
71
  },
愚道 已提交
72 73 74
  externals: {
    '@antv/data-set': 'DataSet',
  },
陈帅 已提交
75 76 77 78 79 80 81
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
愚道 已提交
82 83 84 85
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
86
  disableRedirectHoist: true,
愚道 已提交
87 88 89 90 91
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
陈帅 已提交
92 93
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
愚道 已提交
94 95 96
      ) {
        return localName;
      }
S
sorrycc 已提交
97 98 99 100 101 102 103 104 105
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = antdProPath
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
陈帅 已提交
106
      return localName;
愚道 已提交
107 108
    },
  },
109
  manifest: {
陈帅 已提交
110
    basePath: '/',
111
  },
S
sorrycc 已提交
112

陈帅 已提交
113
  chainWebpack: webpackPlugin,
愚道 已提交
114
};