panzerdp / dmitripavlutin.com-comments

7 stars 0 forks source link

/javascript-module-import-twice/ #60

Open panzerdp opened 3 years ago

panzerdp commented 3 years ago

Written on 03/03/2020 12:14:32

URL: https://dmitripavlutin.com/javascript-module-import-twice/

panzerdp commented 3 years ago

Comment written by Patrick Mualaba on 05/16/2020 19:11:46

Thanks for the great explanation. Question: When a module is imported multiple times in different files and in different folders, I assume that it will not influence the evaluation, since the paths are first resolved to absolute paths i assume? Second: Does the same apply when using named imports (for example function references are strictly equal no matter where they are imported )?

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 05/19/2020 17:37:45

You're welcome @patrick_mualaba:disqus.

If multiple paths access the same module, anyways, the module is evaluated just once. Yep, it applies to default and named imports.

panzerdp commented 3 years ago

Comment written by Balázs Botond on 10/16/2020 12:44:10

Thanks for the excellent explanation!

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 10/16/2020 13:12:29

You're welcome Balazs!

panzerdp commented 3 years ago

Comment written by Suresh Babu on 10/21/2020 16:51:17

Awesome Dmitri Pavlutin.

panzerdp commented 3 years ago

Comment written by Dmitri Pavlutin on 10/21/2020 17:05:04

Thanks Suresh Babu.

Katona commented 3 years ago

Does this module resolution mechanism change when the modules are bundle by Webpack for instance?

panzerdp commented 3 years ago

Does this module resolution mechanism change when the modules are bundle by Webpack for instance?

Most likely not.

gabriel-trc commented 3 years ago

Hello thanks for the explanation. Don't you name the dynamic imports, it works the same way?

uahnbu commented 2 years ago

That's actually my wondering, too. Thank you.

uahnbu commented 2 years ago

So I've dug a little more into it and found out sth that may help with your understanding.

italomg commented 2 years ago

What an excellent, didatic, concentrated explanation of how the import statement works in modern Javascript. Thanks Dmitri, this was very helpful!

panzerdp commented 2 years ago

What an excellent, didatic, concentrated explanation of how the import statement works in modern Javascript. Thanks Dmitri, this was very helpful!

Thanks @italomg! Glad you like the post.