diff --git a/.webpackrc b/.webpackrc index 2aeef9d6ca671649c3d0a7e6656fe3aeaf094b6c..f47c4b7292b3c85a3ca03de1115f9fc00696ecfc 100755 --- a/.webpackrc +++ b/.webpackrc @@ -16,5 +16,6 @@ "html": { "template": "./src/index.ejs" }, + "disableDynamicImport": true, "hash": true } diff --git a/src/common/router.js b/src/common/router.js index 69d3392764c77136344eab9ea35bb66992f08dd1..b88197d6d8ab1b3ac088ef77912015f28c35bb20 100644 --- a/src/common/router.js +++ b/src/common/router.js @@ -1,21 +1,56 @@ -import React from 'react'; +import { createElement } from 'react'; import dynamic from 'dva/dynamic'; import { getMenuData } from './menu'; +let routerDataCache; + +const modelNotExisted = (app, model) => ( + // eslint-disable-next-line + !app._models.some(({ namespace }) => namespace === model) +); + // wrapper of dynamic -const dynamicWrapper = (app, models, component) => dynamic({ - app, - // eslint-disable-next-line no-underscore-dangle - models: () => models.filter(m => !app._models.some(({ namespace }) => namespace === m)).map(m => import(`../models/${m}.js`)), - // add routerData prop - component: () => { - const routerData = getRouterData(app); - return component().then((raw) => { - const Component = raw.default || raw; - return props => ; +const dynamicWrapper = (app, models, component) => { + // () => require('module') + // transformed by babel-plugin-dynamic-import-node-sync + if (component.toString().indexOf('.then(') < 0) { + models.forEach((model) => { + if (modelNotExisted(app, model)) { + // eslint-disable-next-line + app.model(require(`../models/${model}`).default); + } }); - }, -}); + return (props) => { + if (!routerDataCache) { + routerDataCache = getRouterData(app); + } + return createElement(component().default, { + ...props, + routerData: routerDataCache, + }); + }; + } + // () => import('module') + return dynamic({ + app, + models: () => models.filter( + model => modelNotExisted(app, model)).map(m => import(`../models/${m}.js`) + ), + // add routerData prop + component: () => { + if (!routerDataCache) { + routerDataCache = getRouterData(app); + } + return component().then((raw) => { + const Component = raw.default || raw; + return props => createElement(Component, { + ...props, + routerData: routerDataCache, + }); + }); + }, + }); +}; function getFlatMenuData(menus) { let keys = {}; diff --git a/src/rollbar.js b/src/rollbar.js index 21e0b3d8e523179a80375b2e2b4fa66bf5abf2a8..f333309fdbb5162b2a8c91e7df109a58afb7ad40 100644 --- a/src/rollbar.js +++ b/src/rollbar.js @@ -1,6 +1,6 @@ import Rollbar from 'rollbar'; -// Track error by https://sentry.io/ +// Track error by rollbar.com if (location.host === 'preview.pro.ant.design') { Rollbar.init({ accessToken: '033ca6d7c0eb4cc1831cf470c2649971',