ES6 Modules: Exporting and importing performance differences

佐手、 提交于 2019-12-01 17:49:07

No, it's not slower (not by much, of course it has to load one more file, and the IO will take most of the extra time).

An import always loads the whole module, creates all the exported values, and resolves the imported bindings. It doesn't matter whether only one or all the exported bindings are used. It doesn't matter what syntax the import declaration is using. It doesn't even matter whether the resolution goes through the additional index.js file or not, in the end the reference that is used at runtime is exactly the same.

On the contrary, I would consider it a good practise to use such an index.js file if it keeps your modules more maintainable.

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