config.js 3.1 KB
Newer Older
愚道 已提交
1
// https://umijs.org/config/
愚道 已提交
2
import os from 'os';
陈帅 已提交
3
import webpackPlugin from './plugin.config';
愚道 已提交
4
import defaultSettings from '../src/defaultSettings';
陈小聪 已提交
5
import slash from 'slash2';
愚道 已提交
6

陈帅 已提交
7 8 9 10 11 12 13 14 15 16 17 18
const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {
        enable: true, // default false
        default: 'zh-CN', // default zh-CN
        baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
陈帅 已提交
19
      },
陈帅 已提交
20 21
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
22
        webpackChunkName: true,
陈帅 已提交
23
      },
X
xiaoiver 已提交
24 25 26 27 28 29
      pwa: {
        workboxPluginMode: 'InjectManifest',
        workboxOptions: {
          importWorkboxFrom: 'local',
        },
      },
愚道 已提交
30 31 32 33 34 35 36 37 38
      // ...(!process.env.TEST && os.platform() === 'darwin'
      //   ? {
      //       dll: {
      //         include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
      //         exclude: ['@babel/runtime'],
      //       },
      //       hardSource: true,
      //     }
      //   : {}),
陈帅 已提交
39
    },
愚道 已提交
40
  ],
陈帅 已提交
41 42
];

偏右 已提交
43 44
// 针对 preview.pro.ant.design 的 GA 统计代码
// 业务上不需要这个
陈帅 已提交
45 46 47 48 49 50 51 52 53 54 55 56
if (process.env.APP_TYPE === 'site') {
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // add for transfer to umi
  plugins,
陈帅 已提交
57
  define: {
陈帅 已提交
58
    APP_TYPE: process.env.APP_TYPE || '',
陈帅 已提交
59
  },
60
  treeShaking: true,
S
Shuai Chen 已提交
61 62 63
  targets: {
    ie: 11,
  },
愚道 已提交
64
  // 路由配置
愚道 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
  routes: [{
    path: '/user',
    components: ['../layouts/UserLayout'],
    routes: [],
  }, {
    path: '/',
    component: '../layouts/BasicLayout',
    Routes: ['src/pages/Authorized'],
    authority: ['admin', 'user'],
    routes: [
      // dashboard
      {
        path: '/',
        name: 'dashboard',
        icon: 'dashboard',
        component: './BasicDemo',
      },
    ],
  }],
A
afc163 已提交
84 85
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
愚道 已提交
86
  theme: {
A
afc163 已提交
87
    'primary-color': defaultSettings.primaryColor,
愚道 已提交
88
  },
愚道 已提交
89 90 91
  externals: {
    '@antv/data-set': 'DataSet',
  },
陈帅 已提交
92 93 94 95 96 97 98
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
愚道 已提交
99 100 101 102
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
103
  disableRedirectHoist: true,
愚道 已提交
104 105 106 107 108
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
陈帅 已提交
109 110
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
愚道 已提交
111 112 113
      ) {
        return localName;
      }
S
sorrycc 已提交
114 115
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
S
Shuai Chen 已提交
116
        const antdProPath = match[1].replace('.less', '');
陈小聪 已提交
117
        const arr = slash(antdProPath)
S
sorrycc 已提交
118 119 120 121 122
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
陈帅 已提交
123
      return localName;
愚道 已提交
124 125
    },
  },
126
  manifest: {
陈帅 已提交
127
    basePath: '/',
128
  },
S
sorrycc 已提交
129

陈帅 已提交
130
  chainWebpack: webpackPlugin,
愚道 已提交
131
};