@cspell/dynamic-import
TypeScript icon, indicating that this package has built-in type declarations

8.8.3 • Public • Published

@cspell/dynamic-import

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

Install

npm install -S @cspell/dynamic-import

Usage

Example ESM Package

Example loading chalk v5 which is an ESM only module.

TypeScript Common JS

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

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

TypeScript ESM

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

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

Example ESM files

TypeScript Common JS

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

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


Brought to you byStreet Side Software Logo Street Side Software

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @cspell/dynamic-import

    Weekly Downloads

    380,607

    Version

    8.8.3

    License

    MIT

    Unpacked Size

    8.15 kB

    Total Files

    9

    Last publish

    Collaborators

    • jason-dent