config.js 3.27 KB
Newer Older
1 2 3 4 5
// https://umijs.org/config/
import os from 'os';
import webpackPlugin from './plugin.config';
import defaultSettings from '../src/defaultSettings';
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
xiaoiver's avatar
xiaoiver committed
19
      },
20 21 22 23 24 25 26 27 28
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
        webpackChunkName: true,
      },
      pwa: {
        workboxPluginMode: 'InjectManifest',
        workboxOptions: {
          importWorkboxFrom: 'local',
        },
ๆ„š้“'s avatar
ๆ„š้“ committed
29
      },
30 31 32 33 34 35 36 37 38 39
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      moveService: false,
      modifyRequest: true,
      autoAddMenu: true,
    },
ๆ„š้“'s avatar
ๆ„š้“ committed
40
  ],
41 42 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
  // ...(!process.env.TEST && os.platform() === 'darwin'
  //   ? {
  //       dll: {
  //         include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  //         exclude: ['@babel/runtime'],
  //       },
  //       hardSource: true,
  //     }
  //   : {}),
];

// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
// ไธšๅŠกไธŠไธ้œ€่ฆ่ฟ™ไธช
if (process.env.APP_TYPE === 'site') {
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // add for transfer to umi
  plugins,
  define: {
    APP_TYPE: process.env.APP_TYPE || '',
  },
  treeShaking: true,
70 71 72
  targets: {
    ie: 11,
  },
73
  // ่ทฏ็”ฑ้…็ฝฎ
74
  routes: [
75
    {
76
      path: '/user',
77 78
      components: ['../layouts/UserLayout'],
      routes: [],
79
    },
80 81 82
    {
      path: '/',
      component: '../layouts/BasicLayout',
83 84
      Routes: ['src/pages/Authorized'],
      authority: ['admin', 'user'],
85 86 87
      routes: [
        // dashboard
        {
88
          path: '/',
ๆ„š้“'s avatar
ๆ„š้“ committed
89 90 91 92
          name: 'welcome',
          icon: 'smile',
          component: './Welcome',
        },
93 94 95
      ],
    },
  ],
afc163's avatar
afc163 committed
96 97
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
ๆ„š้“'s avatar
ๆ„š้“ committed
98
  theme: {
99
    'primary-color': defaultSettings.primaryColor,
ๆ„š้“'s avatar
ๆ„š้“ committed
100
  },
101 102 103
  externals: {
    '@antv/data-set': 'DataSet',
  },
104 105 106 107 108 109 110
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
111 112 113 114
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },

  chainWebpack: webpackPlugin,
ๆ„š้“'s avatar
ๆ„š้“ committed
143
};