You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CHANGELOG.md
+41
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,47 @@
2
2
3
3
## Unreleased
4
4
5
+
* Add support for `imports` in `package.json` ([#1691](https://github.com/evanw/esbuild/issues/1691))
6
+
7
+
This release adds basic support for the `imports` field in `package.json`. It behaves similarly to the `exports` field but only applies to import paths that start with `#`. The `imports` field provides a way for a package to remap its own internal imports for itself, while the `exports` field provides a way for a package to remap its external exports for other packages. This is useful because the `imports` field respects the currently-configured conditions which means that the import mapping can change at run-time. For example:
8
+
9
+
```
10
+
$ cat entry.mjs
11
+
import '#example'
12
+
13
+
$ cat package.json
14
+
{
15
+
"imports": {
16
+
"#example": {
17
+
"foo": "./example.foo.mjs",
18
+
"default": "./example.mjs"
19
+
}
20
+
}
21
+
}
22
+
23
+
$ cat example.foo.mjs
24
+
console.log('foo is enabled')
25
+
26
+
$ cat example.mjs
27
+
console.log('foo is disabled')
28
+
29
+
$ node entry.mjs
30
+
foo is disabled
31
+
32
+
$ node --conditions=foo entry.mjs
33
+
foo is enabled
34
+
```
35
+
36
+
Now that esbuild supports this feature too, import paths starting with `#` and any provided conditions will be respected when bundling:
* Fix using `npm rebuild` with the `esbuild` package ([#1703](https://github.com/evanw/esbuild/issues/1703))
6
47
7
48
Version 0.13.4 accidentally introduced a regression in the install script where running `npm rebuild` multiple times could fail after the second time. The install script creates a copy of the binary executable using [`link`](https://man7.org/linux/man-pages/man2/link.2.html) followed by [`rename`](https://www.man7.org/linux/man-pages/man2/rename.2.html). Using `link` creates a hard link which saves space on the file system, and `rename` is used for safety since it atomically replaces the destination.
0 commit comments