Conditional Importing In JavaScript
JavaScript
05/08/2021
To conditionally import a module or whatnot, you got to make use of dynamic imports. As an example:
JAVASCRIPT
// In async functionconst module = await import('./someModule')
Pay attention to the import
keyword. If used as a function, it returns a promise.
Knowing that, conditionally importing is then a walk in the park. 🌳
JAVASCRIPT
// In async functionlet someModule if (someCondition) someModule = await import('./someModule')