config.ts 11.4 KB
Newer Older
1
import { IConfig, IPlugin } from 'umi-types';
duanledexianxianxian's avatar
duanledexianxianxian committed
2
import defaultSettings from './defaultSettings'; // https://umijs.org/config/
duanledexianxianxian's avatar
duanledexianxianxian committed
3
import theme from './theme.config';
4

5
import os from 'os';
6
import slash from 'slash2';
7
import webpackPlugin from './plugin.config';
duanledexianxianxian's avatar
duanledexianxianxian committed
8 9 10
const path = require('path');

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

้™ˆๅธ…'s avatar
้™ˆๅธ… committed
13
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env;
14
const plugins: IPlugin[] = [
15 16 17 18 19 20 21 22
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
23 24 25 26 27 28
        // 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
29
      },
30 31 32
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
        webpackChunkName: true,
Yu's avatar
Yu committed
33
        level: 3,
34
      },
35 36 37 38 39 40 41
      pwa: pwa
        ? {
            workboxPluginMode: 'InjectManifest',
            workboxOptions: {
              importWorkboxFrom: 'local',
            },
          }
yaphet's avatar
yaphet committed
42
        : false,
43
      ...(!TEST && os.platform() === 'darwin'
44 45 46
        ? {
            dll: {
              include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
47
              exclude: ['@babel/runtime', 'netlify-lambda'],
48
            },
49
            hardSource: false,
50 51
          }
        : {}),
52 53 54 55 56 57 58 59 60 61
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      moveService: false,
      modifyRequest: true,
      autoAddMenu: true,
    },
ๆ„š้“'s avatar
ๆ„š้“ committed
62
  ],
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
63
]; // ้’ˆๅฏน preview.pro.ant.design ็š„ GA ็ปŸ่ฎกไปฃ็ 
64
// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design ไธ“็”จ็Žฏๅขƒๅ˜้‡๏ผŒ่ฏทไธ่ฆๅœจไฝ ็š„้กน็›ฎไธญไฝฟ็”จๅฎƒใ€‚
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
65

66
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
export default {
  // 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 95 96
  block: {
    defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  },
97
  treeShaking: true,
98 99 100
  targets: {
    ie: 11,
  },
101
  devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false,
102
  // ่ทฏ็”ฑ้…็ฝฎ
103 104 105
  routes: [
    {
      path: '/',
duanledexianxianxian's avatar
duanledexianxianxian committed
106
      component: '../layouts/BlankLayout',
107
      routes: [
duanledexianxianxian's avatar
duanledexianxianxian committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        {
          path: '/user',
          component: '../layouts/UserLayout',
          routes: [
            {
              path: '/user',
              redirect: '/user/login',
            },
            {
              name: 'login',
              path: '/user/login',
              component: './user/login',
            },
            {
              name: 'register-result',
              path: '/user/register-result',
              component: './user/register-result',
            },
            {
              name: 'register',
              path: '/user/register',
              component: './user/register',
            },
          ],
        },
133
        {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
134
          path: '/',
duanledexianxianxian's avatar
duanledexianxianxian committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
          component: '../layouts/BasicLayout',
          Routes: ['src/pages/Authorized'],
          authority: ['admin', 'user'],
          routes: [
            {
              path: '/dashboard',
              name: 'dashboard',
              icon: 'dashboard',
              routes: [
                {
                  name: 'analysis',
                  path: '/dashboard/analysis',
                  component: './dashboard/analysis',
                },
                {
                  name: 'monitor',
                  path: '/dashboard/monitor',
                  component: './dashboard/monitor',
                },
                {
                  name: 'workplace',
                  path: '/dashboard/workplace',
                  component: './dashboard/workplace',
                },
              ],
            },
            {
              path: '/form',
              icon: 'form',
              name: 'form',
              routes: [
                {
                  name: 'basic-form',
                  path: '/form/basic-form',
                  component: './form/basic-form',
                },
                {
                  name: 'step-form',
                  path: '/form/step-form',
                  component: './form/step-form',
                },
                {
                  name: 'advanced-form',
                  path: '/form/advanced-form',
                  component: './form/advanced-form',
                },
              ],
            },
            {
              path: '/list',
              icon: 'table',
              name: 'list',
              routes: [
                {
                  path: '/list/search',
                  name: 'search-list',
                  component: './list/search',
                  routes: [
                    {
                      path: '/list/search',
                      redirect: '/list/search/articles',
                    },
                    {
                      name: 'articles',
                      path: '/list/search/articles',
                      component: './list/search/articles',
                    },
                    {
                      name: 'projects',
                      path: '/list/search/projects',
                      component: './list/search/projects',
                    },
                    {
                      name: 'applications',
                      path: '/list/search/applications',
                      component: './list/search/applications',
                    },
                  ],
                },
                {
                  name: 'table-list',
                  path: '/list/table-list',
                  component: './list/table-list',
                },
                {
                  name: 'basic-list',
                  path: '/list/basic-list',
                  component: './list/basic-list',
                },
                {
                  name: 'card-list',
                  path: '/list/card-list',
                  component: './list/card-list',
                },
              ],
            },
            {
              path: '/profile',
              name: 'profile',
              icon: 'profile',
              routes: [
                {
                  name: 'basic',
                  path: '/profile/basic',
                  component: './profile/basic',
                },
                {
                  name: 'advanced',
                  path: '/profile/advanced',
                  component: './profile/advanced',
                },
              ],
            },
            {
              name: 'result',
              icon: 'check-circle-o',
              path: '/result',
              routes: [
                {
                  name: 'success',
                  path: '/result/success',
                  component: './result/success',
                },
                {
                  name: 'fail',
                  path: '/result/fail',
                  component: './result/fail',
                },
              ],
            },
            {
              name: 'exception',
              icon: 'warning',
              path: '/exception',
              routes: [
                {
                  name: '403',
                  path: '/exception/403',
                  component: './exception/403',
                },
                {
                  name: '404',
                  path: '/exception/404',
                  component: './exception/404',
                },
                {
                  name: '500',
                  path: '/exception/500',
                  component: './exception/500',
                },
              ],
            },
            {
              name: 'account',
              icon: 'user',
              path: '/account',
              routes: [
                {
                  name: 'center',
                  path: '/account/center',
                  component: './account/center',
                },
                {
                  name: 'settings',
                  path: '/account/settings',
                  component: './account/settings',
                },
              ],
            },
            {
              name: 'editor',
              icon: 'highlight',
              path: '/editor',
              routes: [
                {
                  name: 'flow',
                  path: '/editor/flow',
                  component: './editor/flow',
                },
                {
                  name: 'mind',
                  path: '/editor/mind',
                  component: './editor/mind',
                },
                {
                  name: 'koni',
                  path: '/editor/koni',
                  component: './editor/koni',
                },
              ],
            },
duanledexianxianxian's avatar
duanledexianxianxian committed
326 327 328 329 330 331
            {
              name: 'parameter',
              icon: 'highlight',
              path: '/parameter',
              component: './system/parameter',
            },
duanledexianxianxian's avatar
duanledexianxianxian committed
332 333 334 335 336 337
            {
              path: '/',
              redirect: '/dashboard/analysis',
              authority: ['admin', 'user'],
            },
          ],
ๆ„š้“'s avatar
ๆ„š้“ committed
338
        },
339 340 341
      ],
    },
  ],
afc163's avatar
afc163 committed
342 343
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
duanledexianxianxian's avatar
duanledexianxianxian committed
344
  theme,
345 346 347 348 349 350 351
  // proxy: {
  //   '/server/api/': {
  //     target: 'https://preview.pro.ant.design/',
  //     changeOrigin: true,
  //     pathRewrite: { '^/server': '' },
  //   },
  // },
352 353 354 355
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
356 357 358
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
359 360 361 362 363
    getLocalIdent: (
      context: {
        resourcePath: string;
      },
      localIdentName: string,
duanledexianxianxian's avatar
duanledexianxianxian committed
364
      localName: string,
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
365
    ) => {
366 367 368 369 370 371 372
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
373

374
      const match = context.resourcePath.match(/src(.*)/);
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
375

376 377 378 379
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
380 381
          .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
          .map((a: string) => a.toLowerCase());
382 383
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
384

385 386 387 388 389 390
      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
391
  uglifyJSOptions,
392
  chainWebpack: webpackPlugin,
duanledexianxianxian's avatar
duanledexianxianxian committed
393 394 395 396 397 398 399 400 401 402
  // ้…็ฝฎ webpack ็š„ resolve.alias ๅฑžๆ€ง ้ป˜่ฎคsrc=>@
  alias: {
    src: path.join(__dirname, '../src'),
    components: path.join(__dirname, '../src', 'components'),
    utils: path.join(__dirname, '../src', 'utils'),
    assets: path.join(__dirname, '../src', 'assets'),
    themes: path.join(__dirname, '../src', 'themes'),
    config: path.join(__dirname, '../src', '../config'),
    public: path.join(__dirname, '../public'),
  },
ไฝ•ไน's avatar
ไฝ•ไน committed
403
} as IConfig;