Dynamically import JavaScript module using ES6 syntax? -


this question has answer here:

is es2015+, how can dynamically import module?

e.g. instead of...

import {someclass} 'lib/whatever/some-class'; 

i don't know path @ runtime, want have path stored in variable, , want import specific thing module:

function dodynamicstuff(path) {     let importedthing = ...; //import * importedthing path;     let thingireallywant = importedthing.someexportedvariable;      ... } 

i'm not sure syntax use, or if it's possible @ all. tried using let importedthing = require(path); we're not using requirejs.

es2015 not support dynamic imports design.

in current javascript module systems, have execute code in order find out imports , exports are. main reason why ecmascript 6 breaks systems: building module system language, can syntactically enforce static module structure.

...

a module’s structure being static means can determine imports , exports @ compile time (statically) – have @ source code, don’t have execute it.

from ecmascript 6 modules: final syntax

to dynamically import module have explicitly use module loaders (like requirejs or systemjs)


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -