Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
onkarj366yFor you guys to understand my need more properly -
I got this idea from Angular's ngModules where you can import everything in single ngModule decorated class and then you can access all that in all the other files under that module! -
@onkarj The imports are needed because you code in a modular fashion.
Every module is a box for itself and within the module it does not know what usable stuff is outside (except for some global stuff).
What you are asking is possible to do, but will lead to seriously bad code!
Btw: When you add an import at the top of your module, it will add this import's code only ONCE in the whole project.
The import is just a way to tell the module you need access to this other module, but br other module is ONLY ONCE in your transpiled code.
It's similar to the #include directive (with include guard in the .h file of course) in C/C++. -
Modules are only imported once and then cached. These are the kind of things that cause so little overhead, you may as well ignore it... If you are looking into performance tuning you are looking at the wrong end. Even when a "module" is not executed in a node context, build tools like webpack cache your modules anyway...
-
@onkarj In your stackoverflow post you mention that you want to basically import all modules in a single file and then import that file with all exports in your modules, Instead of having separate imports for each module you want...
Sorry if I am blunt but that just dumb. Why would you do that? Thats just not how modules work. Importing modules is too hard for you? Come on seriously? Every editor worth its salt will give you a option to import modules automatically so there is literally 0 work. How is this even a thing? -
You. Just. Don't.
I am suspecting an XY problem. Your attempted solution won't help you at all. Full stop. -
hitko31466yAs long as you only install module once (check out package.json's "resolutions" field), it will get imported only once, and all 'require' calls (or bundlers) will return a reference to the same object.
-
onkarj366yThe whole idea was just to know, how exactly Angular does that, when you import things in NgModule, you don't need to import them anywhere in the other files under that module. How does this work?
Just wanted to know this. But, people here seem to just throw some basic import export knowledge that I already know. -
hitko31466y@onkarj Where did you get Angular from? You were asking about Node the whole time... So let's get this straight: you actually want to know how Angular does it so that you can import components and services in @Module, and use them across your components without specifically importing them each time?
Hello, a question about Node project -
How to import node libraries only once and use them all over the project.
I have asked it on StackOverflow, link to it
https://stackoverflow.com/questions...
If you guys have any idea for it, please, share!
question
nodejs commonjs module