Skip to content

Commit

Permalink
fix: improve Dynamic Import README.md (#4178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Feb 15, 2023
1 parent 7d56d43 commit 4ad1133
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/dynamic-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,34 @@ npm install -S @cspell/dynamic-import

## Usage

**TypeScript**
### Example ESM Package

Example loading [chalk v5](https://www.npmjs.com/package/chalk) which is an ESM only module.

**TypeScript Common JS**

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

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

**TypeScript ESM**

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

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

### Example ESM files

**TypeScript Common JS**

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

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

<!--- @@inject: ../../static/footer.md --->
Expand All @@ -29,3 +53,5 @@ Brought to you by <a href="https://streetsidesoftware.com" title="Street Side So
</p>

<!--- @@inject-end: ../../static/footer.md --->

<!--- cspell:dictionaries typescript --->

0 comments on commit 4ad1133

Please sign in to comment.