config.ts 3.57 KB
Newer Older
陈帅's avatar
陈帅 committed
1 2 3
import { IConfig, IPlugin } from 'umi-types';

import defaultSettings from './defaultSettings';
4 5
// https://umijs.org/config/
import slash from 'slash2';
陈小聪's avatar
陈小聪 committed
6
import webpackPlugin from './plugin.config';
陈帅's avatar
陈帅 committed
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

陈小聪's avatar
陈小聪 committed
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
      },
陈帅's avatar
陈帅 committed
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,
陈帅's avatar
陈帅 committed
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
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
107 108 109
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
陈帅's avatar
陈帅 committed
110 111 112 113
    getLocalIdent: (
      context: {
        resourcePath: string;
      },
afc163's avatar
afc163 committed
114
      _: string,
陈帅's avatar
陈帅 committed
115 116
      localName: string,
    ) => {
117 118 119 120 121 122 123
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
陈帅's avatar
陈帅 committed
124

125
      const match = context.resourcePath.match(/src(.*)/);
陈帅's avatar
陈帅 committed
126

127 128 129 130
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
陈帅's avatar
陈帅 committed
131 132
          .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
          .map((a: string) => a.toLowerCase());
133 134
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
陈帅's avatar
陈帅 committed
135

136 137 138 139 140 141 142
      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
  chainWebpack: webpackPlugin,
afc163's avatar
afc163 committed
143 144 145 146 147 148 149 150 151
  /*
  proxy: {
    '/server/api/': {
      target: 'https://preview.pro.ant.design/',
      changeOrigin: true,
      pathRewrite: { '^/server': '' },
    },
  },
  */
何乐's avatar
何乐 committed
152
} as IConfig;