Skip to content

Commit 6f0e360

Browse files
committed
chore(README.md): document "main" field
1 parent d1272d4 commit 6f0e360

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ The option is
9595
}
9696
```
9797

98+
### Main Field
99+
100+
```javascript
101+
{
102+
"mainFields": ["module", "main"]
103+
}
104+
```
105+
106+
Quoting esbuild's documentation:
107+
108+
* `main` - This is [the standard field](https://docs.npmjs.com/files/package.json#main) for all packages that are meant to be used with node. The name main is hard-coded in to node's module resolution logic itself. Because it's intended for use with node, it's reasonable to expect that the file path in this field is a CommonJS-style module.
109+
* `module` - This field came from a [proposal](https://github.com/dherman/defense-of-dot-js/blob/f31319be735b21739756b87d551f6711bd7aa283/proposal.md) for how to integrate ECMAScript modules into node. Because of this, it's reasonable to expect that the file path in this field is an ECMAScript-style module. This proposal wasn't adopted by node (node uses "type": "module" instead) but it was adopted by major bundlers because ECMAScript-style modules lead to better tree shaking, or dead code removal.
110+
* `browser` - This field came from a [proposal](https://gist.github.com/defunctzombie/4339901/49493836fb873ddaa4b8a7aa0ef2352119f69211) that allows bundlers to replace node-specific files or modules with their browser-friendly versions. It lets you specify an alternate browser-specific entry point. Note that it is possible for a package to use both the browser and module field together (see the note below).
111+
98112
### Errors
99113

100114
* `Error: Package subpath '.' is not defined by "exports" in` - occurs when resolving without `conditionNames`.

0 commit comments

Comments
 (0)