config.js 3.68 KB
Newer Older
ๆ„š้“'s avatar
ๆ„š้“ committed
1
// https://umijs.org/config/
2
import os from 'os';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
3
import webpackPlugin from './plugin.config';
4
import defaultSettings from '../src/defaultSettings';
5
import slash from 'slash2';
6

7
const { pwa, primaryColor } = defaultSettings;
8 9
// 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;
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
      },
xiaohuoni's avatar
xiaohuoni committed
24 25 26 27 28
      routes: {
        update(routes) {
          return [...require('../src/pages/_routes'), ...routes];
        },
      },
29 30
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
31
        webpackChunkName: true,
32
        level: 3,
33
      },
34 35 36 37 38 39 40
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
yaphet's avatar
yaphet committed
41
        : false,
42
      ...(!TEST && os.platform() === 'darwin'
43 44 45
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
46
              exclude: ['@babel/runtime', 'netlify-lambda'],
47
            },
48
            hardSource: false,
49 50 51
          }
        : {}),
    },
ๆ„š้“'s avatar
ๆ„š้“ committed
52
  ],
xiaohuoni's avatar
xiaohuoni committed
53 54 55 56 57 58 59 60 61 62 63 64
  [
    'umi-plugin-authorize',
    {
      authorize: [
        {
          guard: ['src/pages/Auth'],
          include: /\//,
          exclude: /\/user/i,
        },
      ],
    },
  ],
65 66
];

ๅๅณ's avatar
ๅๅณ committed
67
// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
68 69
// 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') {
70 71 72 73 74 75 76 77 78 79 80
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // add for transfer to umi
  plugins,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
81
  define: {
82 83
    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
84
  },
85
  treeShaking: true,
Shuai Chen's avatar
Shuai Chen committed
86 87 88
  targets: {
    ie: 11,
  },
ๆ„š้“'s avatar
ๆ„š้“ committed
89
  // ่ทฏ็”ฑ้…็ฝฎ
xiaohuoni's avatar
xiaohuoni committed
90
  // routes: pageRoutes,
afc163's avatar
afc163 committed
91 92
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
ๆ„š้“'s avatar
ๆ„š้“ committed
93
  theme: {
94
    'primary-color': primaryColor,
ๆ„š้“'s avatar
ๆ„š้“ committed
95
  },
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
96 97 98 99 100 101 102
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
103 104 105 106
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
107
  disableRedirectHoist: true,
108 109 110 111 112
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
113 114
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
115 116 117
      ) {
        return localName;
      }
sorrycc's avatar
sorrycc committed
118 119
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
Shuai Chen's avatar
Shuai Chen committed
120
        const antdProPath = match[1].replace('.less', '');
121
        const arr = slash(antdProPath)
sorrycc's avatar
sorrycc committed
122 123 124 125 126
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
127
      return localName;
128 129
    },
  },
130
  manifest: {
131
    basePath: '/',
132
  },
sorrycc's avatar
sorrycc committed
133

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