config.js 3.04 KB
Newer Older
ๆ„š้“'s avatar
ๆ„š้“ committed
1
// https://umijs.org/config/
2 3
import os from 'os';
import pageRoutes from './router.config';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
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
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
23
      },
24 25
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
26
        webpackChunkName: true,
27
      },
28 29 30 31 32 33 34 35
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
        : {},
36
      ...(!TEST && os.platform() === 'darwin'
37 38 39 40 41
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
              exclude: ['@babel/runtime'],
            },
42
            hardSource: false,
43 44 45
          }
        : {}),
    },
ๆ„š้“'s avatar
ๆ„š้“ committed
46
  ],
47 48
];

ๅๅณ's avatar
ๅๅณ committed
49 50
// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
// ไธšๅŠกไธŠไธ้œ€่ฆ่ฟ™ไธช
51
if (APP_TYPE === 'site') {
52 53 54 55 56 57 58 59 60 61 62
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // add for transfer to umi
  plugins,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
63
  define: {
64
    APP_TYPE: APP_TYPE || '',
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
65
  },
66
  treeShaking: true,
Shuai Chen's avatar
Shuai Chen committed
67 68 69
  targets: {
    ie: 11,
  },
ๆ„š้“'s avatar
ๆ„š้“ committed
70
  // ่ทฏ็”ฑ้…็ฝฎ
71
  routes: pageRoutes,
afc163's avatar
afc163 committed
72 73
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
ๆ„š้“'s avatar
ๆ„š้“ committed
74
  theme: {
75
    'primary-color': primaryColor,
ๆ„š้“'s avatar
ๆ„š้“ committed
76
  },
77 78
  externals: {
    '@antv/data-set': 'DataSet',
79 80 81 82
    // if is production externals react react-dom and bizcharts
    ...(NODE_ENV === 'production'
      ? { react: 'React', 'react-dom': 'ReactDOM', bizcharts: 'BizCharts' }
      : {}),
83
  },
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
84 85 86 87 88 89 90
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
91 92 93 94
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
95
  disableRedirectHoist: true,
96 97 98 99 100
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
101 102
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
103 104 105
      ) {
        return localName;
      }
sorrycc's avatar
sorrycc committed
106 107
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
Shuai Chen's avatar
Shuai Chen committed
108
        const antdProPath = match[1].replace('.less', '');
109
        const arr = slash(antdProPath)
sorrycc's avatar
sorrycc committed
110 111 112 113 114
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
115
      return localName;
116 117
    },
  },
118
  manifest: {
119
    basePath: '/',
120
  },
sorrycc's avatar
sorrycc committed
121

้™ˆๅธ…'s avatar
้™ˆๅธ… committed
122
  chainWebpack: webpackPlugin,
ๆ„š้“'s avatar
ๆ„š้“ committed
123
};