diff options
author | 2023-09-13 20:43:39 -0700 | |
---|---|---|
committer | 2023-09-13 20:43:39 -0700 | |
commit | c99caccdb2e1bb961b13766ec7ebb9907763e364 (patch) | |
tree | cbc65806656c2b2765666e96a168f5613adf9bb4 /docs/runtime/modules.md | |
parent | 22f14129e5f8e0328b200ce3a8573dbd7c9562c4 (diff) | |
download | bun-c99caccdb2e1bb961b13766ec7ebb9907763e364.tar.gz bun-c99caccdb2e1bb961b13766ec7ebb9907763e364.tar.zst bun-c99caccdb2e1bb961b13766ec7ebb9907763e364.zip |
More docs & helptext cleanup (#5229)
* wip
* Flesh out resolution docs
* Polish
* More
* WIP
* WIP
* WIP
* Document --watch
Diffstat (limited to 'docs/runtime/modules.md')
-rw-r--r-- | docs/runtime/modules.md | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/docs/runtime/modules.md b/docs/runtime/modules.md index a876a5a2b..fe8bb8c64 100644 --- a/docs/runtime/modules.md +++ b/docs/runtime/modules.md @@ -184,18 +184,38 @@ Once it finds the `foo` package, Bun reads the `package.json` to determine how t Whichever one of these conditions occurs _first_ in the `package.json` is used to determine the package's entrypoint. -Bun respects subpath [`"exports"`](https://nodejs.org/api/packages.html#subpath-exports) and [`"imports"`](https://nodejs.org/api/packages.html#imports). Specifying any subpath in the `"exports"` map will prevent other subpaths from being importable. +Bun respects subpath [`"exports"`](https://nodejs.org/api/packages.html#subpath-exports) and [`"imports"`](https://nodejs.org/api/packages.html#imports). ```jsonc#package.json { "name": "foo", "exports": { - ".": "./index.js", - "./package.json": "./package.json" // subpath + ".": "./index.js" } } ``` +Subpath imports and conditional imports work in conjunction with each other. + +``` +{ + "name": "foo", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + } + } +} +``` + +As in Node.js, Specifying any subpath in the `"exports"` map will prevent other subpaths from being importable; you can only import files that are explicitly exported. Given the `package.json` above: + +```ts +import stuff from "foo"; // this works +import stuff from "foo/index.mjs"; // this doesn't +``` + {% callout %} **Shipping TypeScript** — Note that Bun supports the special `"bun"` export condition. If your library is written in TypeScript, you can publish your (un-transpiled!) TypeScript files to `npm` directly. If you specify your package's `*.ts` entrypoint in the `"bun"` condition, Bun will directly import and execute your TypeScript source files. {% /callout %} |