如何在ES2015+中动态导入模块?
例如,不是...
import {SomeClass} from 'lib/whatever/some-class';
我在运行时不知道路径,因此我想将路径存储在变量中,并从该模块导入特定内容:
function doDynamicStuff(path) {
let importedThing = ...; //import * as importedThing from path;
let thingIReallyWant = importedThing.someExportedVariable;
...
}
我不确定要使用哪种语法,或者是否可以完全做到这一点。我尝试使用let importedThing = require(path);
但我们没有使用RequireJS
。
node
,我们使用Aurelia
。 - Josh M.