Skip to content

Commit

Permalink
docs(Configuration): explain more on the condition names (#6330)
Browse files Browse the repository at this point in the history
* explain more on the condition names

* Update src/content/configuration/resolve.mdx

Co-authored-by: Sam Chen <[email protected]>

* Update resolve.mdx

Co-authored-by: Sam Chen <[email protected]>
  • Loading branch information
tanhauhau and chenxsan authored Aug 23, 2022
1 parent 4eb09ae commit 59c6cea
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/content/configuration/resolve.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,52 @@ module.exports = {
};
```

Webpack will match [export conditions](https://nodejs.org/api/packages.html#conditional-exports) that are listed within the `resolve.conditionNames` array.

The key order in the `exports` field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.

For example,

**package.json**

```json
{
"name": "foo",
"exports": {
".": {
"import": "./index-import.js",
"require": "./index-require.js",
"node": "./index-node.js"
},
"./bar": {
"node": "./bar-node.js",
"require": "./bar-require.js"
},
"./baz": {
"import": "./baz-import.js",
"node": "./baz-node.js"
}
}
}
```

**webpack.config.js**

```js
module.exports = {
//...
resolve: {
conditionNames: ['require', 'node'],
},
};
```

importing

- `'foo'` will resolve to `'foo/index-require.js'`
- `'foo/bar'` will resolve to `'foo/bar-node.js'` as the `"node"` key comes before `"require"` key in the conditional exports object.
- `'foo/baz'` will resolve to `'foo/baz-node.js'`

### resolve.descriptionFiles

`[string] = ['package.json']`
Expand Down

1 comment on commit 59c6cea

@vercel
Copy link

@vercel vercel bot commented on 59c6cea Aug 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.