config.ts 4.22 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,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
45 46 47 48 49 50
      // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
      // dll features https://webpack.js.org/plugins/dll-plugin/
      // dll: {
      //   include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
      //   exclude: ['@babel/runtime', 'netlify-lambda'],
      // },
51 52 53 54 55 56 57 58 59 60
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      moveService: false,
      modifyRequest: true,
      autoAddMenu: true,
    },
ๆ„š้“'s avatar
ๆ„š้“ committed
61
  ],
afc163's avatar
afc163 committed
62
];
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
63

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

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

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

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

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