config.js 3.49 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 10
// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST } = process.env;
11

12 13 14 15 16 17 18 19 20 21 22 23
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
24
      },
25 26
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
27
        webpackChunkName: true,
28
        level: 3,
29
      },
30 31 32 33 34 35 36
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
yaphet's avatar
yaphet committed
37
        : false,
38
      ...(!TEST && os.platform() === 'darwin'
39 40 41
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
42
              exclude: ['@babel/runtime', 'netlify-lambda'],
43
            },
44
            hardSource: false,
45 46 47
          }
        : {}),
    },
ๆ„š้“'s avatar
ๆ„š้“ committed
48
  ],
49 50
];

ๅๅณ's avatar
ๅๅณ committed
51
// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
52 53
// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
54 55 56 57 58 59 60 61 62 63 64
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // add for transfer to umi
  plugins,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
65
  define: {
66 67
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
68
  },
69
  treeShaking: true,
Shuai Chen's avatar
Shuai Chen committed
70 71 72
  targets: {
    ie: 11,
  },
73
  devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
ๆ„š้“'s avatar
ๆ„š้“ committed
74
  // ่ทฏ็”ฑ้…็ฝฎ
75
  routes: pageRoutes,
afc163's avatar
afc163 committed
76 77
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
ๆ„š้“'s avatar
ๆ„š้“ committed
78
  theme: {
79
    'primary-color': primaryColor,
ๆ„š้“'s avatar
ๆ„š้“ committed
80
  },
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
81 82 83 84 85 86 87
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
88 89 90 91
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
92
  disableRedirectHoist: true,
93 94 95 96 97
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
98 99
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
100 101 102
      ) {
        return localName;
      }
sorrycc's avatar
sorrycc committed
103 104
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
Shuai Chen's avatar
Shuai Chen committed
105
        const antdProPath = match[1].replace('.less', '');
106
        const arr = slash(antdProPath)
sorrycc's avatar
sorrycc committed
107 108 109 110 111
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
112
      return localName;
113 114
    },
  },
115
  manifest: {
116
    basePath: '/',
117
  },
sorrycc's avatar
sorrycc committed
118

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