config.js 3.11 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
const { APP_TYPE, TEST } = process.env;
9

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

ๅๅณ's avatar
ๅๅณ committed
66 67
// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
// ไธšๅŠกไธŠไธ้œ€่ฆ่ฟ™ไธช
68
if (APP_TYPE === 'site') {
69 70 71 72 73 74 75 76 77 78 79
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

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

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