按需加载

出于性能的考虑,我们会对模块和组件进行按需加载。

按需加载组件

通过 umi/dynamic 接口实现,比如:

  1. import dynamic from 'umi/dynamic';
  2. const delay = (timeout) => new Promise(resolve => setTimeout(resolve, timeout));
  3. const App = dynamic({
  4. loader: async function() {
  5. await delay(/* 1s */1000);
  6. return () => <div>I will render after 1s</div>;
  7. },
  8. });

按需加载模块

通过 import() 实现,比如:

  1. import('g2').then(() => {
  2. // do something with g2
  3. });