ES6 Modules: Exporting and importing performance differences

前端 未结 1 1736
悲哀的现实
悲哀的现实 2021-01-12 05:56

I have some components in my vue project. I don\'t like import loader from \'@/components/someComponent1/someComponent1.vue\'; because it\'s a lot to write and

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 06:47

    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.

    0 讨论(0)
提交回复
热议问题