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
docs(configuration): document default conditionNames by mode, target, and dependency type
The resolve.conditionNames documentation was missing information about
its default values and how they change based on mode, target, and
dependency type. This adds:
- Base conditions (webpack + mode + target-specific)
- Per-dependency type conditions table (ESM, CJS, worker, CSS)
- resolveLoader conditionNames defaults reference
Ref: #7560
Made-with: Cursor
Copy file name to clipboardExpand all lines: src/content/configuration/resolve.mdx
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -305,6 +305,44 @@ export default {
305
305
306
306
Webpack will match [export conditions](https://nodejs.org/api/packages.html#conditional-exports) that are listed within the `resolve.conditionNames` array.
307
307
308
+
#### Default values
309
+
310
+
The default `conditionNames` are composed dynamically based on the [`mode`](/configuration/mode/) and [`target`](/configuration/target/) configuration:
311
+
312
+
The base conditions always include:
313
+
314
+
- `"webpack"` — always present.
315
+
- `"production"` or `"development"` — based on the current [`mode`](/configuration/mode/) (`"production"` is used when mode is `"none"` or `"production"`).
316
+
317
+
Additional conditions are appended depending on the [`target`](/configuration/target/):
318
+
319
+
| Target property | Condition |
320
+
| ---------------- | ------------ |
321
+
| `webworker` | `"worker"` |
322
+
| `node` | `"node"` |
323
+
| `web` | `"browser"` |
324
+
| `electron` | `"electron"` |
325
+
| `nwjs` | `"nwjs"` |
326
+
327
+
For example, with `target:"web"` (the default) and `mode:"production"`, the base `conditionNames` defaults to `["webpack", "production", "browser"]`.
328
+
329
+
#### Per-dependency type conditions
330
+
331
+
Webpack further adjusts `conditionNames` through [`resolve.byDependency`](/configuration/resolve/#resolvebydependency) depending on how a module is imported. The `"..."` token inherits from the base conditions above.
For instance, when a file uses `import` in a project with `target: "web"` and `mode: "production"`, the final resolved conditions are `["import", "module", "webpack", "production", "browser"]`.
341
+
342
+
T> The `resolveLoader` option uses different defaults for `conditionNames`: `["loader", "require", "node"]`. See [resolveLoader](#resolveloader).
343
+
344
+
#### Condition matching
345
+
308
346
The key order in the `exports` field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.
309
347
310
348
For example,
@@ -349,6 +387,8 @@ importing
349
387
- `'foo/bar'` will resolve to `'foo/bar-node.js'` as the `"node"` key comes before `"require"` key in the conditional exports object.
350
388
- `'foo/baz'` will resolve to `'foo/baz-node.js'`
351
389
390
+
#### Custom conditions
391
+
352
392
If you want to add your custom field names while still retaining the default Webpack values, you can use `"..."`:
0 commit comments