Skip to content

Commit 04c18fd

Browse files
authored
docs(configuration): add Rule.with (#7368)
1 parent d2b268c commit 04c18fd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/content/configuration/module.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,37 @@ module.exports = {
15031503

15041504
W> `resolve.fullySpecified` doesn't affect requests from [mainFields](/configuration/resolve/#resolvemainfields), [aliasFields](/configuration/resolve/#resolvealiasfields) or [aliases](/configuration/resolve/#resolvealias).
15051505

1506+
## Rule.with
1507+
1508+
<Badge text="v5.92.0+" />
1509+
1510+
A [`Condition`](#condition) that allows you to match the imports based on specific conditions provided with the `with` keyword, enabling different rules to be applied based on the content type.
1511+
1512+
**webpack.config.js**
1513+
1514+
```javascript
1515+
module.exports = {
1516+
// ...
1517+
module: {
1518+
rules: [
1519+
{
1520+
// Handles imports with the condition "with { type: 'json' }"
1521+
with: { type: 'json' },
1522+
loader: require.resolve('./loader-assert.js'),
1523+
},
1524+
],
1525+
},
1526+
};
1527+
```
1528+
1529+
**index.js**
1530+
1531+
```javascript
1532+
import one from './pkg-1.json' with { type: 'json' };
1533+
```
1534+
1535+
In this example, `Rule.with` is used to apply `loader-assert.js` to any module imported with the condition `with { type: "json" }`.
1536+
15061537
## Condition
15071538

15081539
Conditions can be one of these:

0 commit comments

Comments
 (0)