Skip to content

Commit f6b5f90

Browse files
authored
docs: add Rule.assert (#7367)
1 parent 7729b52 commit f6b5f90

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/content/configuration/module.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,35 @@ The order of evaluation is as follows:
722722
2. [`rules`](#rulerules)
723723
3. [`oneOf`](#ruleoneof)
724724

725+
## Rule.assert
726+
727+
A [`Condition`](#condition) that allows you to match the import assertion of a dependency and apply specific rules based on the assertion type.
728+
729+
**webpack.config.js**
730+
731+
```javascript
732+
module.exports = {
733+
// ...
734+
module: {
735+
rules: [
736+
{
737+
// Handles imports with the assertion "assert { type: 'json' }"
738+
assert: { type: 'json' },
739+
loader: require.resolve('./loader-assert.js'),
740+
},
741+
],
742+
},
743+
};
744+
```
745+
746+
**index.js**
747+
748+
```javascript
749+
import one from './pkg-1.json' assert { type: 'json' };
750+
```
751+
752+
In this example, `Rule.assert` is used to apply `loader-assert.js` to any module imported with the assertion `assert { type: "json" }`, ensuring that JSON files are processed correctly.
753+
725754
## Rule.enforce
726755

727756
`string`

0 commit comments

Comments
 (0)