mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
@@ -276,7 +276,7 @@ await Bun.build({
|
||||
|
||||
## Path re-mapping
|
||||
|
||||
In the spirit of treating TypeScript as a first-class citizen, the Bun runtime will re-map import paths according to the [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) field in `tsconfig.json`. This is a major divergence from Node.js, which doesn't support any form of import path re-mapping.
|
||||
Bun supports import path re-mapping through TypeScript's [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) in `tsconfig.json`, which works well with editors. If you aren't a TypeScript user, you can achieve the same behavior by using a [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) in your project root.
|
||||
|
||||
```json tsconfig.json icon="file-json"
|
||||
{
|
||||
@@ -289,7 +289,16 @@ In the spirit of treating TypeScript as a first-class citizen, the Bun runtime w
|
||||
}
|
||||
```
|
||||
|
||||
If you aren't a TypeScript user, you can create a [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) in your project root to achieve the same behavior.
|
||||
Bun also supports [Node.js-style subpath imports](https://nodejs.org/api/packages.html#subpath-imports) in `package.json`, where mapped paths must start with `#`. This approach doesn’t work as well with editors, but both options can be used together.
|
||||
|
||||
```json package.json icon="file-json"
|
||||
{
|
||||
"imports": {
|
||||
"#config": "./config.ts", // map specifier to file
|
||||
"#components/*": "./components/*" // wildcard matching
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<Accordion title="Low-level details of CommonJS interop in Bun">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user