npm.io
10.3.3 • Published 3d ago

@cspell/dynamic-import

Licence
MIT
Version
10.3.3
Deps
2
Size
8 kB
Vulns
0
Weekly
0
Stars
1.7K

@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 CommonJS

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 CommonJS

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

Keywords