Skip to content

Commit e0ac8d0

Browse files
committed
import example
1 parent 916d7df commit e0ac8d0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

docs/javascript/foo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 42;

docs/javascript/imports.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ Now you can reference the imported `confetti` anywhere on the page.
1212
Inputs.button("Throw confetti!", {reduce: () => confetti()})
1313
```
1414

15-
You can also import JavaScript from local ES modules.
15+
You can also import JavaScript from local ES modules. For example, if this is `foo.js`:
1616

1717
```js no-run
18+
export const foo = 42;
19+
```
20+
21+
Then you can say
22+
23+
```js show
1824
import {foo} from "./foo.js"
1925
```
2026

27+
and the imported value of `foo` is: ${foo}.
28+
2129
This allows you to move code out of Markdown and into vanilla JavaScript files that can be shared by multiple pages — or even another application. And you can write tests for your code.
2230

2331
TK There is a [bug](https://github.com/observablehq/cli/issues/115) where npm protocol imports don’t work from local ES modules.

0 commit comments

Comments
 (0)