config.js 2.76 KB
Newer Older
愚道's avatar
愚道 committed
1
// https://umijs.org/config/
愚道's avatar
愚道 committed
2 3
import os from 'os';
import pageRoutes from './router.config';
陈帅's avatar
陈帅 committed
4
import webpackPlugin from './plugin.config';
愚道's avatar
愚道 committed
5
import defaultSettings from '../src/defaultSettings';
6
import slash from 'slash2';
愚道's avatar
愚道 committed
7

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

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

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

陈帅's avatar
陈帅 committed
114
  chainWebpack: webpackPlugin,
愚道's avatar
愚道 committed
115
};