v0.1.4
A dynamic imports polyfill for Deno Deploy and compiled executables
Attributes
Includes Deno configuration
Repository
Current version released
2 years ago
🐎 Dynamic import ponyfill!
A ponyfill for using dynamic imports in context without, like Deno Deploy, Deno compiled executables (see #1) and older browsers (see #4).
Notes
- The
assert
option does not yet work (see #3). - Only the
"imports"
field from import maps works, the"scopes"
will not. - JSX will work if configured in the
deno.json
ordeno.jsonc
files, in Deno Deploy these are the only ones supported, but Deno compiled executables still have the same limitation. import.meta
will be an empty object.
Example
import { importModule } from 'https://deno.land/x/dynamic_import_ponyfill@v0.1.4/mod.ts'
if (Math.random() > 0.5) {
await importModule('./foo.ts')
} else {
await importModule('./bar.ts')
}
This module also exports an awesome function which evaluates code from a string containing import
and exports
statements.
import { importString } from 'https://deno.land/x/dynamic_import_ponyfill@v0.1.4/mod.ts'
console.log(await importString('export const foo = "bar"'))
Options
interface ImportModuleOptions {
/** Force the use of the ponyfill even when native dynamic import could be used. */
force?: boolean
}
interface ImportStringOptions {
/** The URL to use as a base for imports and exports in the string. */
base?: URL | string
}