config.ts 3.85 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 70
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
71

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

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

131 132 133 134
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
135 136
          .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
          .map((a: string) => a.toLowerCase());
137 138
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
139

140 141 142 143 144 145 146
      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
  chainWebpack: webpackPlugin,
afc163's avatar
afc163 committed
147 148 149 150 151 152 153 154 155
  /*
  proxy: {
    '/server/api/': {
      target: 'https://preview.pro.ant.design/',
      changeOrigin: true,
      pathRewrite: { '^/server': '' },
    },
  },
  */
ไฝ•ไน's avatar
ไฝ•ไน committed
156
} as IConfig;