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
Copy file name to clipboardExpand all lines: src/content/configuration/module.mdx
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1503,6 +1503,37 @@ module.exports = {
1503
1503
1504
1504
W> `resolve.fullySpecified` doesn't affect requests from [mainFields](/configuration/resolve/#resolvemainfields), [aliasFields](/configuration/resolve/#resolvealiasfields) or [aliases](/configuration/resolve/#resolvealias).
1505
1505
1506
+
## Rule.with
1507
+
1508
+
<Badgetext="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
+
importonefrom'./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" }`.
0 commit comments