config.ts 4.04 KB
Newer Older
1 2 3
import { IConfig, IPlugin } from 'umi-types';

import defaultSettings from './defaultSettings';
4 5
// https://umijs.org/config/
import slash from 'slash2';
6
import webpackPlugin from './plugin.config';
7

้™ˆๅธ…'s avatar
้™ˆๅธ… committed
8 9 10
const { pwa, primaryColor } = defaultSettings;

// preview.pro.ant.design only do not use in your production ;
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
11
// preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
afc163's avatar
afc163 committed
12 13 14
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;

const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
Yu's avatar
Yu committed
15

16
const plugins: IPlugin[] = [
17 18 19 20 21 22 23 24
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
25 26 27 28 29 30
        // default false
        enable: true,
        // default zh-CN
        default: 'zh-CN',
        // default true, when it is true, will use `navigator.language` overwrite default
        baseNavigator: true,
xiaoiver's avatar
xiaoiver committed
31
      },
32 33 34
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
        webpackChunkName: true,
Yu's avatar
Yu committed
35
        level: 3,
36
      },
37 38 39 40 41 42 43
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
yaphet's avatar
yaphet committed
44
        : false,
afc163's avatar
afc163 committed
45 46 47 48
      dll: {
        include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
        exclude: ['@babel/runtime', 'netlify-lambda'],
      },
49 50 51 52 53 54 55 56 57 58
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      moveService: false,
      modifyRequest: true,
      autoAddMenu: true,
    },
ๆ„š้“'s avatar
ๆ„š้“ committed
59
  ],
afc163's avatar
afc163 committed
60
];
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
61

afc163's avatar
afc163 committed
62 63
// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
if (isAntDesignProPreview) {
64 65 66 67 68 69
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
70 71 72 73 74 75
  plugins.push([
    'umi-plugin-pro',
    {
      serverUrl: 'https://ant-design-pro.netlify.com',
    },
  ]);
76
}
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
77

78 79
export default {
  plugins,
80 81 82
  block: {
    defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  },
afc163's avatar
afc163 committed
83
  hash: true,
84 85 86
  targets: {
    ie: 11,
  },
afc163's avatar
afc163 committed
87 88
  devtool: isAntDesignProPreview ? 'source-map' : false,
  // umi routes: https://umijs.org/zh/guide/router.html
89 90 91 92
  routes: [
    {
      path: '/',
      component: '../layouts/BasicLayout',
93 94
      Routes: ['src/pages/Authorized'],
      authority: ['admin', 'user'],
95 96
      routes: [
        {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
97
          path: '/',
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
98 99 100
          name: 'welcome',
          icon: 'smile',
          component: './Welcome',
ๆ„š้“'s avatar
ๆ„š้“ committed
101
        },
102 103 104
        {
          component: './404',
        },
105 106
      ],
    },
107 108 109
    {
      component: './404',
    },
110
  ],
afc163's avatar
afc163 committed
111
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
ๆ„š้“'s avatar
ๆ„š้“ committed
112
  theme: {
Yu's avatar
Yu committed
113
    'primary-color': primaryColor,
ๆ„š้“'s avatar
ๆ„š้“ committed
114
  },
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
115 116 117 118
  define: {
    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 ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
  },
119 120 121 122
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
123 124 125
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
126 127 128 129
    getLocalIdent: (
      context: {
        resourcePath: string;
      },
afc163's avatar
afc163 committed
130
      _: string,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
131 132
      localName: string,
    ) => {
133 134 135 136 137 138 139
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
140

141
      const match = context.resourcePath.match(/src(.*)/);
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
142

143 144 145 146
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
147 148
          .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
          .map((a: string) => a.toLowerCase());
149 150
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
151

152 153 154 155 156 157 158
      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
  chainWebpack: webpackPlugin,
afc163's avatar
afc163 committed
159 160 161 162 163 164 165 166 167
  /*
  proxy: {
    '/server/api/': {
      target: 'https://preview.pro.ant.design/',
      changeOrigin: true,
      pathRewrite: { '^/server': '' },
    },
  },
  */
ไฝ•ไน's avatar
ไฝ•ไน committed
168
} as IConfig;