Replying to @coderbyheart

However your code that does this is most likely a shorthand switch statement:

let module switch(name) { case 'awesome': module = require('my-awesome') }

Because you do not really want to load an arbitrary module, but one that is very
much already known.

Mon, 23 Aug 2021 07:51:45 UTC

1 reply

Replying to @coderbyheart

You know which modules are "dynamically" loaded, so you can convert logic like
this at compile time to a static import construct as shown above, by iterating
over all your possible imports and generating the module loader.

That way you can use import with "dynamic" modules.