dynamic-import-support
enable dynamic imports in node.js
import'./whatever'
Install
npm install dynamic-import-support
Usage
Use dynamic-import-support/register
to enable import()
in all modules loaded after the current one:
Use dynamic-import-support
to transform some source code containing import()
calls:
var dynamicImport = === `function _import(p){return Promise.resolve().then(function(){return require(p)})} _import('./whatever').then(function (exports) { console.log(exports) })`
It uses js-tokens instead of a full parser, so it's very quick.
Some patterns aren't supported though.
For example, import()
inside a template string won't be transformed.
If this is a problem, please open an issue and we'll figure out how to make it work :)