From 70bf403be2276e89ea560e97f415716164b340a1 Mon Sep 17 00:00:00 2001 From: Lars Windolf Date: Sat, 23 Dec 2023 20:57:46 +0100 Subject: [PATCH] Create Javascript Module Import.md --- .../Javascript Module Import.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/Javascript Examples/Javascript Module Import.md diff --git a/examples/Javascript Examples/Javascript Module Import.md b/examples/Javascript Examples/Javascript Module Import.md new file mode 100644 index 000000000..5b35ee636 --- /dev/null +++ b/examples/Javascript Examples/Javascript Module Import.md @@ -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//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.