Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add Rule.assert #7367

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/content/configuration/module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,35 @@ The order of evaluation is as follows:
2. [`rules`](#rulerules)
3. [`oneOf`](#ruleoneof)

## Rule.assert

A [`Condition`](#condition) taht allows you to match the import assertion of a dependency and apply specific rules based on the assertion type.

**webpack.config.js**

```javascript
module.exports = {
// ...
module: {
rules: [
{
// Handles imports with the assertion "assert { type: 'json' }"
assert: { type: 'json' },
loader: require.resolve('./loader-assert.js'),
},
],
},
};
```

**index.js**

```javascript
import one from './pkg-1.json' assert { type: 'json' };
```

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.

## Rule.enforce

`string`
Expand Down
Loading