config.ts 4.37 KB
Newer Older
1
// https://umijs.org/config/
2
import os from 'os';
3
import slash from 'slash2';
ไฝ•ไน's avatar
ไฝ•ไน committed
4
import { IPlugin, IConfig } from 'umi-types';
5 6
import defaultSettings from './defaultSettings';
import webpackPlugin from './plugin.config';
7

Yu's avatar
Yu committed
8
const { pwa, primaryColor } = defaultSettings;
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
9 10
// preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
11
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env;
Yu's avatar
Yu committed
12

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
      },
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'
43 44 45
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
46
              exclude: ['@babel/runtime', 'netlify-lambda'],
47
            },
48
            hardSource: false,
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
  ],
62 63 64
];

// ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
65 66
// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
67 68 69 70 71 72 73
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
74 75 76 77 78 79 80 81 82 83

const uglifyJSOptions =
  NODE_ENV === 'production'
    ? {
        uglifyOptions: {
          // remove console.* except console.error
          compress: {
            drop_console: true,
            pure_funcs: ['console.error'],
          },
84
        },
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
85 86
      }
    : {};
87 88 89 90 91

export default {
  // add for transfer to umi
  plugins,
  define: {
92 93
    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 ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
94 95
  },
  treeShaking: true,
96 97 98
  targets: {
    ie: 11,
  },
99
  devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
100
  // ่ทฏ็”ฑ้…็ฝฎ
101 102 103 104
  routes: [
    {
      path: '/',
      component: '../layouts/BasicLayout',
105 106
      Routes: ['src/pages/Authorized'],
      authority: ['admin', 'user'],
107 108
      routes: [
        {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
109
          path: '/',
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
110 111 112
          name: 'Analysis',
          icon: 'dashboard',
          component: './analysis',
ๆ„š้“'s avatar
ๆ„š้“ committed
113
        },
114 115 116
      ],
    },
  ],
afc163's avatar
afc163 committed
117 118
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
ๆ„š้“'s avatar
ๆ„š้“ committed
119
  theme: {
Yu's avatar
Yu committed
120
    'primary-color': primaryColor,
ๆ„š้“'s avatar
ๆ„š้“ committed
121
  },
122 123 124 125 126 127 128
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
129 130 131 132
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
133 134 135
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
136 137 138 139 140 141 142
    getLocalIdent: (
      context: {
        resourcePath: string;
      },
      localIdentName: string,
      localName: string,
    ) => {
143 144 145 146 147 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;
      }
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
155 156
          .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
          .map((a: string) => a.toLowerCase());
157 158 159 160 161 162 163 164
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
165
  uglifyJSOptions,
166
  chainWebpack: webpackPlugin,
ไฝ•ไน's avatar
ไฝ•ไน committed
167
} as IConfig;