When using dynamic imports, can I define what I want to import like regular imports?
For example:
import Person from '/classes.js'
As dynamic:
await import('Person from /classes.js') //Incorrect obviously
When using dynamic imports, can I define what I want to import like regular imports?
For example:
import Person from '/classes.js'
As dynamic:
await import('Person from /classes.js') //Incorrect obviously
Share
Improve this question
asked Nov 8, 2018 at 16:01
MojimiMojimi
3,18112 gold badges65 silver badges133 bronze badges
2 Answers
Reset to default 9Dynamic imports will hand you everything from within the module. You can use destructuring the extract the pieces you want.
const { Person } = await import('/classes.js');
You can try this when you need to import some specific file.
const moduleSpecifier = '/classes.js';
import(moduleSpecifier)
.then(someModule => someModule.myFucntion());