config.js 2.76 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';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
6
import Dart from './dart';
7

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
      },
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
      },
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',
        },
      },
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
  ],
44 45
];

ๅๅณ's avatar
ๅๅณ committed
46 47
// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
// ไธšๅŠกไธŠไธ้œ€่ฆ่ฟ™ไธช
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
  // ่ทฏ็”ฑ้…็ฝฎ
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
    ...Dart,
ๆ„š้“'s avatar
ๆ„š้“ committed
73
  },
74 75 76
  externals: {
    '@antv/data-set': 'DataSet',
  },
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
77 78 79 80 81 82 83
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
84 85 86 87
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
88
  disableRedirectHoist: true,
89 90 91 92 93
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
94 95
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
96 97 98
      ) {
        return localName;
      }
sorrycc's avatar
sorrycc committed
99 100 101 102 103 104 105 106 107
      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, '-');
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
108
      return localName;
109 110
    },
  },
111
  manifest: {
112
    basePath: '/',
113
  },
sorrycc's avatar
sorrycc committed
114

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