Skip to content

Commit ed8e68f

Browse files
add info about exports field in deno.json (#2420)
1 parent 2c13c7a commit ed8e68f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

runtime/fundamentals/configuration.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,45 @@ works as well:
487487
}
488488
```
489489

490+
## Exports
491+
492+
The `exports` field in the `deno.json` file allows you to define which paths of
493+
your package should be publicly accessible. This is particularly useful for
494+
controlling the API surface of your package and ensuring that only the intended
495+
parts of your code are exposed to users.
496+
497+
```jsonc title="deno.json"
498+
{
499+
"exports": "./src/mod.ts" // A default entry point
500+
}
501+
```
502+
503+
You can also define multiple entry points:
504+
505+
```json title="deno.json"
506+
{
507+
"exports": {
508+
"./module1": "./src/module1.ts",
509+
"./module2": "./src/module2.ts",
510+
".": "./src/mod.ts" // Default entry point
511+
}
512+
}
513+
```
514+
515+
This configuration will:
516+
517+
- expose `module1` and `module2` as entry points for your package,
518+
- allow importing any file from the `utils` directory using a wildcard. This
519+
means users can import these modules using the specified paths, while other
520+
files in your package remain private.
521+
522+
To use the exports in your code, you can import them like this:
523+
524+
```ts title="example.ts"
525+
import * as module_1 from "@example/my-package/module1";
526+
import * as module_2 from "@example/my-package/module2";
527+
```
528+
490529
## An example `deno.json` file
491530

492531
```json

0 commit comments

Comments
 (0)