Why is exporting/importing default ES module properties faster than names module properties?

纵然是瞬间 提交于 2019-12-01 20:04:49

问题


I'm reading the Material UI documentation, and it states:

Notice that in the above example, we used: import RaisedButton from 'material-ui/RaisedButton'; instead of import {RaisedButton} from 'material-ui'; This will make your build process faster and your build output smaller.

I cannot find any justification for why the use of default exports makes the build process faster or build output smaller.

My manager is asking us to refrain from using default exports, however a smaller build size is an important target for this project. I mentioned this quote by Material UI, and they said to find proof. I'd like some proof, please, as my attempts to compile it with Babel have shown default to be larger if anything.


回答1:


The key thing is not whether the module has a default export or not, but the fact that you import a module that includes all the Material UI Components (the material-ui module) instead of the module that includes only the RaisedButton component (the material-ui/RaisedButton module).

To be absolutely clear: We should be using the module that only includes a single component, i.e. material-ui/RaisedButton.



来源:https://stackoverflow.com/questions/48432754/why-is-exporting-importing-default-es-module-properties-faster-than-names-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!