Unverified Commit 61c60a29 authored by 偏右's avatar 偏右 Committed by GitHub

Config code split (#562)

* change to one bundle first

* config code split by babel-plugin-dynamic-import-node-sync

* refactor

* Use roadbog disableDynamicImport

* fix typo

* Fix require default
parent 668074c8
...@@ -16,5 +16,6 @@ ...@@ -16,5 +16,6 @@
"html": { "html": {
"template": "./src/index.ejs" "template": "./src/index.ejs"
}, },
"disableDynamicImport": true,
"hash": true "hash": true
} }
import React from 'react'; import { createElement } from 'react';
import dynamic from 'dva/dynamic'; import dynamic from 'dva/dynamic';
import { getMenuData } from './menu'; import { getMenuData } from './menu';
let routerDataCache;
const modelNotExisted = (app, model) => (
// eslint-disable-next-line
!app._models.some(({ namespace }) => namespace === model)
);
// wrapper of dynamic // wrapper of dynamic
const dynamicWrapper = (app, models, component) => dynamic({ const dynamicWrapper = (app, models, component) => {
app, // () => require('module')
// eslint-disable-next-line no-underscore-dangle // transformed by babel-plugin-dynamic-import-node-sync
models: () => models.filter(m => !app._models.some(({ namespace }) => namespace === m)).map(m => import(`../models/${m}.js`)), if (component.toString().indexOf('.then(') < 0) {
// add routerData prop models.forEach((model) => {
component: () => { if (modelNotExisted(app, model)) {
const routerData = getRouterData(app); // eslint-disable-next-line
return component().then((raw) => { app.model(require(`../models/${model}`).default);
const Component = raw.default || raw; }
return props => <Component {...props} routerData={routerData} />;
}); });
}, 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) { function getFlatMenuData(menus) {
let keys = {}; let keys = {};
......
import Rollbar from 'rollbar'; import Rollbar from 'rollbar';
// Track error by https://sentry.io/ // Track error by rollbar.com
if (location.host === 'preview.pro.ant.design') { if (location.host === 'preview.pro.ant.design') {
Rollbar.init({ Rollbar.init({
accessToken: '033ca6d7c0eb4cc1831cf470c2649971', accessToken: '033ca6d7c0eb4cc1831cf470c2649971',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment