Skip to content

Commit

Permalink
Create Javascript Module Import.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf authored Dec 23, 2023
1 parent fd3201f commit 70bf403
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/Javascript Examples/Javascript Module Import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Importing ESM modules

Here is how you import modules without a packager.

### Find ESM for a package

If you download packages via `npm` check the `node_modules/<name>/dist` directory for files with
- extension `.es.js`
- extension `.esm.js`

### Import ESM module

Now there are two variants depending on the module having a default export or not:

1. `import * as Example from "./example.js";`
2. `import { Example } from "./example.js";`

Check the `export` statement in the module wether it has `as default` or not. If yes, use variant #1.

0 comments on commit 70bf403

Please sign in to comment.