config.js 2.68 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// https://umijs.org/config/
import { defineConfig } from '@umijs/max';
import { join } from 'path';
import defaultSettings from './defaultSettings';
import proxy from './proxy';
import routes from './routes';
import authRoutes from './authRoutes';

const { REACT_APP_ENV } = process.env;
let temp = [];
function getList(tree) {
  for (let item in tree) {
    if (tree[item].routes) {
      getList(tree[item].routes);
    } else {
      temp.push(tree[item]);
    }
  }
  return temp;
}

const keepalive = getList(authRoutes)
  ?.filter((it) => {
    return it?.path && !it?.unkeepalive;
  })
  .map((it) => it.path);

TZW's avatar
TZW committed
28
//console.log(keepalive);
wuhao's avatar
wuhao committed
29 30 31 32 33 34 35 36 37 38 39 40 41

export default defineConfig({
  outputPath: 'package',
  hash: true,
  antd: {
    compact: true,
  },
  history: {
    type: 'hash',
  },
  manifest: {
    basePath: '/',
  },
TZW's avatar
TZW committed
42
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
wuhao's avatar
wuhao committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
  initialState: {},
  model: {},
  keepalive: keepalive,
  layout: {
    // https://umijs.org/zh-CN/plugins/plugin-layout
    locale: false,
    siderWidth: 208,
    ...defaultSettings,
  },
  // https://umijs.org/zh-CN/plugins/plugin-locale
  locale: {
    // default zh-CN
    default: 'zh-CN',
    antd: true,
    // default true, when it is true, will use `navigator.language` overwrite default
    baseNavigator: true,
  },
  // umi routes: https://umijs.org/docs/routing
  routes,
  access: {},
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // 如果不想要 configProvide 动态设置主题需要把这个设置为 default
    // 只有设置为 variable, 才能使用 configProvide 动态设置主色调
    // https://ant.design/docs/react/customize-theme-variable-cn
    'root-entry-name': 'variable',
  },
  ignoreMomentLocale: true,
  proxy: proxy[REACT_APP_ENV || 'dev'],
  // Fast Refresh 热更新
  fastRefresh: true,
  presets: ['umi-presets-pro'],
  openAPI: [
    {
      requestLibPath: "import { request } from '@umijs/max'",
      // 或者使用在线的版本
      // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
      schemaPath: join(__dirname, 'oneapi.json'),
      mock: false,
    },
    {
      requestLibPath: "import { request } from '@umijs/max'",
      schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json',
      projectName: 'swagger',
    },
  ],
TZW's avatar
TZW committed
89 90 91 92 93 94 95 96 97
  chainWebpack: function (config, { webpack }) {
    // 线上环境就去除console输出
    process.env.NODE_ENV === 'production' &&
      config.optimization.minimizer('terser').tap((args) => {
        args[0].terserOptions.compress.drop_console = true;
        args[0].terserOptions.compress.drop_debugger = true;
        return args;
      });
  },
wuhao's avatar
wuhao committed
98
});