From d6fd5bd9b19e7db3e19206c66768eeee56ce1a0f Mon Sep 17 00:00:00 2001 From: teee32 Date: Tue, 17 Mar 2026 10:35:47 +0800 Subject: [PATCH 1/2] 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: webpack/webpack.js.org#7560 Made-with: Cursor --- src/content/configuration/resolve.mdx | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/content/configuration/resolve.mdx b/src/content/configuration/resolve.mdx index 38d5b9b8d5e3..535ded058b16 100644 --- a/src/content/configuration/resolve.mdx +++ b/src/content/configuration/resolve.mdx @@ -305,6 +305,44 @@ export default { Webpack will match [export conditions](https://nodejs.org/api/packages.html#conditional-exports) that are listed within the `resolve.conditionNames` array. +#### Default values + +The default `conditionNames` are composed dynamically based on the [`mode`](/configuration/mode/) and [`target`](/configuration/target/) configuration: + +The base conditions always include: + +- `"webpack"` — always present. +- `"production"` or `"development"` — based on the current [`mode`](/configuration/mode/) (`"production"` is used when mode is `"none"` or `"production"`). + +Additional conditions are appended depending on the [`target`](/configuration/target/): + +| Target property | Condition | +| ---------------- | ------------ | +| `webworker` | `"worker"` | +| `node` | `"node"` | +| `web` | `"browser"` | +| `electron` | `"electron"` | +| `nwjs` | `"nwjs"` | + +For example, with `target: "web"` (the default) and `mode: "production"`, the base `conditionNames` defaults to `["webpack", "production", "browser"]`. + +#### Per-dependency type conditions + +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. + +| Dependency type | `conditionNames` | Used for | +| ---------------------------------- | ----------------------------------- | ----------------------------------------------- | +| `esm`, `wasm`, `loaderImport` | `["import", "module", "..."]` | ESM `import` statements, WebAssembly, loader imports | +| `commonjs`, `amd`, `loader`, `unknown`, `undefined` | `["require", "module", "..."]` | `require()` calls, AMD, and other dependency types | +| `worker` | `["worker", "import", "module", "..."]` | `new Worker()` expressions | +| `css-import` | `["webpack", , "style"]` | CSS `@import` statements | + +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"]`. + +T> The `resolveLoader` option uses different defaults for `conditionNames`: `["loader", "require", "node"]`. See [resolveLoader](#resolveloader). + +#### Condition matching + 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, @@ -349,6 +387,8 @@ importing - `'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'` +#### Custom conditions + If you want to add your custom field names while still retaining the default Webpack values, you can use `"..."`: **webpack.config.js** From ba4f666859769f66238bc8425e6cc5afc4517ba5 Mon Sep 17 00:00:00 2001 From: teee32 Date: Tue, 17 Mar 2026 11:05:57 +0800 Subject: [PATCH 2/2] style: fix prettier formatting in markdown tables Made-with: Cursor --- src/content/configuration/resolve.mdx | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/content/configuration/resolve.mdx b/src/content/configuration/resolve.mdx index 535ded058b16..537c28e596ec 100644 --- a/src/content/configuration/resolve.mdx +++ b/src/content/configuration/resolve.mdx @@ -316,13 +316,13 @@ The base conditions always include: Additional conditions are appended depending on the [`target`](/configuration/target/): -| Target property | Condition | -| ---------------- | ------------ | -| `webworker` | `"worker"` | -| `node` | `"node"` | -| `web` | `"browser"` | -| `electron` | `"electron"` | -| `nwjs` | `"nwjs"` | +| Target property | Condition | +| --------------- | ------------ | +| `webworker` | `"worker"` | +| `node` | `"node"` | +| `web` | `"browser"` | +| `electron` | `"electron"` | +| `nwjs` | `"nwjs"` | For example, with `target: "web"` (the default) and `mode: "production"`, the base `conditionNames` defaults to `["webpack", "production", "browser"]`. @@ -330,12 +330,12 @@ For example, with `target: "web"` (the default) and `mode: "production"`, the ba 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. -| Dependency type | `conditionNames` | Used for | -| ---------------------------------- | ----------------------------------- | ----------------------------------------------- | -| `esm`, `wasm`, `loaderImport` | `["import", "module", "..."]` | ESM `import` statements, WebAssembly, loader imports | -| `commonjs`, `amd`, `loader`, `unknown`, `undefined` | `["require", "module", "..."]` | `require()` calls, AMD, and other dependency types | -| `worker` | `["worker", "import", "module", "..."]` | `new Worker()` expressions | -| `css-import` | `["webpack", , "style"]` | CSS `@import` statements | +| Dependency type | `conditionNames` | Used for | +| --------------------------------------------------- | --------------------------------------- | ---------------------------------------------------- | +| `esm`, `wasm`, `loaderImport` | `["import", "module", "..."]` | ESM `import` statements, WebAssembly, loader imports | +| `commonjs`, `amd`, `loader`, `unknown`, `undefined` | `["require", "module", "..."]` | `require()` calls, AMD, and other dependency types | +| `worker` | `["worker", "import", "module", "..."]` | `new Worker()` expressions | +| `css-import` | `["webpack", , "style"]` | CSS `@import` statements | 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"]`.