1.0.0 • Published 8 months ago

@codetypo/dynamic-import v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@codetypo/dynamic-import

A small library to assist with dynamically loading CommonJS and ESM Modules from either CommonJS or ESM Modules.

Install

npm install -S @codetypo/dynamic-import

Usage

Example ESM Package

Example loading chalk v5 which is an ESM only module.

TypeScript Common JS

import { dynamicImport } from '@codetypo/dynamic-import';

const pChalk = dynamicImport<typeof import('chalk')>('chalk', __dirname);

TypeScript ESM

import { dynamicImport } from '@codetypo/dynamic-import';

const pChalk = dynamicImport<typeof import('chalk')>('chalk', import.meta.url);

Example ESM files

TypeScript Common JS

import { dynamicImport } from '@codetypo/dynamic-import';

const pIndex = dynamicImport<typeof import('../esm/index.mjs')>('../esm/index.mjs', __dirname);

1.0.0

8 months ago