As far as I understand, webpack (and other similar bundlers) guarantee that if the same module is needed across various parts of the application:
- The code will only load once
- Each time the same module is required, a new instance is created instead of all sharing the same scope
First off, are my assumptions correct? And if so, is it inefficient to have multiple instances of the same module being created?
For example, in my upcoming app, I will be using ThreeJS - a substantial library. Many modules within the app will need to require this library.
Is it considered bad practice to keep requiring a library like this? Should I pass a single instance from module to module rather than requiring it multiple times?
I am curious about any common approaches for addressing this potential issue if indeed it is problematic.