Skip to content

Commit d6fd5bd

Browse files
teee32GG ZIBLAKING
authored andcommitted
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
1 parent 19fe5df commit d6fd5bd

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/content/configuration/resolve.mdx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,44 @@ export default {
305305
306306
Webpack will match [export conditions](https://nodejs.org/api/packages.html#conditional-exports) that are listed within the `resolve.conditionNames` array.
307307
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.
332+
333+
| Dependency type | `conditionNames` | Used for |
334+
| ---------------------------------- | ----------------------------------- | ----------------------------------------------- |
335+
| `esm`, `wasm`, `loaderImport` | `["import", "module", "..."]` | ESM `import` statements, WebAssembly, loader imports |
336+
| `commonjs`, `amd`, `loader`, `unknown`, `undefined` | `["require", "module", "..."]` | `require()` calls, AMD, and other dependency types |
337+
| `worker` | `["worker", "import", "module", "..."]` | `new Worker()` expressions |
338+
| `css-import` | `["webpack", <mode>, "style"]` | CSS `@import` statements |
339+
340+
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+
308346
The key order in the `exports` field is significant. During condition matching, earlier entries have higher priority and take precedence over later entries.
309347
310348
For example,
@@ -349,6 +387,8 @@ importing
349387
- `'foo/bar'` will resolve to `'foo/bar-node.js'` as the `"node"` key comes before `"require"` key in the conditional exports object.
350388
- `'foo/baz'` will resolve to `'foo/baz-node.js'`
351389
390+
#### Custom conditions
391+
352392
If you want to add your custom field names while still retaining the default Webpack values, you can use `"..."`:
353393
354394
**webpack.config.js**

0 commit comments

Comments
 (0)