Skip to main content

Dynamic import ponyfill

RepositoryRegistryDocumentation

A dynamic imports polyfill for Deno Deploy and compiled executables.

Example

Note

JSX and import maps will work if configured in deno.json[c].

Important

Use statically analyzable imports when posible to avoid unnecessary work.

import { dynamicImport } from 'https://deno.land/x/import/mod.ts';

if (Math.random() > 0.5) {
    await dynamicImport('./foo.ts');
} else {
    await dynamicImport('./bar.ts');
}

It also has a function to evaluate modules from strings.

import { importString } from 'https://deno.land/x/import/mod.ts';

console.log(await importString('export const foo = "bar"'));

And you can pass parameters to them.

console.log(
    await importString('console.log(foo)', { parameters: { foo: 'bar' } }),
);

🦕 Happy dynamic importing!