From f417777995681939ccf8b8152de37cc8ca34bffa Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 24 Aug 2024 17:59:44 +0530 Subject: [PATCH 1/3] docs: add `Rule.assert` --- src/content/configuration/module.mdx | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/content/configuration/module.mdx b/src/content/configuration/module.mdx index f1f46526ab1f..46ec65d6b4ba 100644 --- a/src/content/configuration/module.mdx +++ b/src/content/configuration/module.mdx @@ -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 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` From c81829409652a8351dfeb27b6842e46e892d2d02 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 24 Aug 2024 18:01:34 +0530 Subject: [PATCH 2/3] docs: update example --- src/content/configuration/module.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/configuration/module.mdx b/src/content/configuration/module.mdx index 46ec65d6b4ba..b184c72c30db 100644 --- a/src/content/configuration/module.mdx +++ b/src/content/configuration/module.mdx @@ -734,7 +734,7 @@ module.exports = { module: { rules: [ { - // Handles imports with the assertion type "json" + // Handles imports with the assertion "assert { type: 'json' }" assert: { type: 'json' }, loader: require.resolve('./loader-assert.js'), }, From be34ce94027f47e4399137134c1136e7ad523ffa Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 24 Aug 2024 18:04:32 +0530 Subject: [PATCH 3/3] Update src/content/configuration/module.mdx --- src/content/configuration/module.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/configuration/module.mdx b/src/content/configuration/module.mdx index b184c72c30db..8f02ae730869 100644 --- a/src/content/configuration/module.mdx +++ b/src/content/configuration/module.mdx @@ -724,7 +724,7 @@ The order of evaluation is as follows: ## 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. +A [`Condition`](#condition) that allows you to match the import assertion of a dependency and apply specific rules based on the assertion type. **webpack.config.js**