为什么导出/导入默认ES模块属性比命名模块属性更快? [英] Why is exporting/importing default ES module properties faster than names module properties?

查看:68
本文介绍了为什么导出/导入默认ES模块属性比命名模块属性更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Material UI文档,它说明:

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


请注意,在上面的示例中,我们使用了:
从'material-ui / RaisedButton'导入RaisedButton; 而不是
从'material-ui'导入{RaisedButton}; 这将使你的构建
进程更快,你的构建输出更小。

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.

我的经理要求我们不要使用默认导出,但是更小的构建大小是这个项目的重要目标。我通过Material UI提到了这个引用,他们说要找到证据。我想要一些证据,因为我尝试用Babel编译它已经显示默认如果有的话更大。

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.

推荐答案

关键是模块是否具有默认导出,而是导入包含所有材质UI组件的模块( material-ui 模块)而不是只包含 RaisedButton 组件的模块( material-ui / RaisedButton 模块)。

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).

绝对清楚:我们应该使用仅包含单个组件的模块,即 material-ui / RaisedButton

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

这篇关于为什么导出/导入默认ES模块属性比命名模块属性更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆