config.ts 4.52 KB
Newer Older
1
// https://umijs.org/config/
愚道's avatar
愚道 committed
2
import os from 'os';
3
import slash from 'slash2';
何乐's avatar
何乐 committed
4
import { IPlugin, IConfig } from 'umi-types';
陈小聪's avatar
陈小聪 committed
5 6
import defaultSettings from './defaultSettings';
import webpackPlugin from './plugin.config';
陈帅's avatar
陈帅 committed
7 8 9
const { pwa, primaryColor } = defaultSettings;

// preview.pro.ant.design only do not use in your production ;
陈帅's avatar
陈帅 committed
10
// preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
Yu's avatar
Yu committed
11

陈帅's avatar
陈帅 committed
12
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env;
陈小聪's avatar
陈小聪 committed
13
const plugins: IPlugin[] = [
14 15 16 17 18 19 20 21
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {
陈帅's avatar
陈帅 committed
22 23 24 25 26 27
        // 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
28
      },
29 30 31
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
        webpackChunkName: true,
Yu's avatar
Yu committed
32
        level: 3,
33
      },
陈帅's avatar
陈帅 committed
34 35 36 37 38 39 40
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
yaphet's avatar
yaphet committed
41
        : false,
42
      ...(!TEST && os.platform() === 'darwin'
陈帅's avatar
陈帅 committed
43 44 45
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
46
              exclude: ['@babel/runtime', 'netlify-lambda'],
陈帅's avatar
陈帅 committed
47
            },
48
            hardSource: false,
陈帅's avatar
陈帅 committed
49 50
          }
        : {}),
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
  ],
陈帅's avatar
陈帅 committed
62
]; // 针对 preview.pro.ant.design 的 GA 统计代码
63
// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
陈帅's avatar
陈帅 committed
64

65
if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
66 67 68 69 70 71 72
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}
陈帅's avatar
陈帅 committed
73 74 75 76 77 78 79 80 81 82

const uglifyJSOptions =
  NODE_ENV === 'production'
    ? {
        uglifyOptions: {
          // remove console.* except console.error
          compress: {
            drop_console: true,
            pure_funcs: ['console.error'],
          },
信鑫-King's avatar
信鑫-King committed
83
        },
陈帅's avatar
陈帅 committed
84 85
      }
    : {};
86
export default {
duanledexianxianxian's avatar
test  
duanledexianxianxian committed
87
  publicPath: "/test",
88 89 90
  // add for transfer to umi
  plugins,
  define: {
91 92
    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 专用环境变量,请不要在你的项目中使用它。
93 94
  },
  treeShaking: true,
95 96 97
  targets: {
    ie: 11,
  },
陈帅's avatar
陈帅 committed
98
  devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
99
  // 路由配置
100 101 102 103
  routes: [
    {
      path: '/',
      component: '../layouts/BasicLayout',
104 105
      Routes: ['src/pages/Authorized'],
      authority: ['admin', 'user'],
106 107
      routes: [
        {
陈帅's avatar
陈帅 committed
108
          path: '/',
陈帅's avatar
陈帅 committed
109 110 111
          name: 'welcome',
          icon: 'smile',
          component: './Welcome',
愚道's avatar
愚道 committed
112
        },
duanledexianxianxian's avatar
test  
duanledexianxianxian committed
113 114 115 116 117 118
        {
          path: '/demo',
          name: 'demo',
          icon: 'smile',
          component: './demo',
        },
119 120 121
      ],
    },
  ],
afc163's avatar
afc163 committed
122 123
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
愚道's avatar
愚道 committed
124
  theme: {
Yu's avatar
Yu committed
125
    'primary-color': primaryColor,
愚道's avatar
愚道 committed
126
  },
127 128 129 130 131 132 133
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
愚道's avatar
愚道 committed
134 135 136 137
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
138 139 140
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
陈帅's avatar
陈帅 committed
141 142 143 144 145 146 147
    getLocalIdent: (
      context: {
        resourcePath: string;
      },
      localIdentName: string,
      localName: string,
    ) => {
148 149 150 151 152 153 154
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
陈帅's avatar
陈帅 committed
155

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

158 159 160 161
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
陈帅's avatar
陈帅 committed
162 163
          .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
          .map((a: string) => a.toLowerCase());
164 165
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
陈帅's avatar
陈帅 committed
166

167 168 169 170 171 172
      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
信鑫-King's avatar
信鑫-King committed
173
  uglifyJSOptions,
174
  chainWebpack: webpackPlugin,
何乐's avatar
何乐 committed
175
} as IConfig;