config.js 2.9 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
import slash from 'slash2';
愚道 已提交
7

陈帅 已提交
8
const { pwa, primaryColor } = defaultSettings;
9
const { NODE_ENV, APP_TYPE, TEST } = process.env;
陈帅 已提交
10

陈帅 已提交
11 12 13 14 15 16 17 18 19 20 21 22
const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      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
陈帅 已提交
23
      },
陈帅 已提交
24 25
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
26
        webpackChunkName: true,
陈帅 已提交
27
        level: 3,
陈帅 已提交
28
      },
陈帅 已提交
29 30 31 32 33 34 35 36
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
        : {},
37
      ...(!TEST && os.platform() === 'darwin'
陈帅 已提交
38 39 40 41 42
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
              exclude: ['@babel/runtime'],
            },
43
            hardSource: false,
陈帅 已提交
44 45 46
          }
        : {}),
    },
愚道 已提交
47
  ],
陈帅 已提交
48 49
];

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

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

陈帅 已提交
120
  chainWebpack: webpackPlugin,
愚道 已提交
121
};