React 16.6引入了Lazy
,它可以使代码具有悬念...我记得Webpack不能摇晃非定向导入文件(例如异步导入),但是该怎么办呢?
import React, {lazy, Suspense} from 'react';
const OtherComponent = lazy(() => import('./OtherComponent'));
function MyComponent() {
return (
<Suspense fallback={<div>Loading...</div>}>
<OtherComponent />
</Suspense>
);
}
示例取自here
是否在OtherComponent
中进行了摇树?