Skip to content

Commit fe0952d

Browse files
docs: add commonjsMagicComments docs (#11752)
* docs: add commonjsMagicComments docs * Apply suggestion from @chenjiahan * Apply suggestion from @chenjiahan --------- Co-authored-by: neverland <[email protected]>
1 parent 145aca4 commit fe0952d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

website/docs/en/config/module.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,31 @@ export default {
164164
};
165165
```
166166
167+
### module.parser.javascript.commonjsMagicComments
168+
169+
<PropertyType type="boolean" defaultValueList={[{ defaultValue: 'false' }]} />
170+
<ApiMeta addedVersion="1.5.6" />
171+
172+
Enable [Magic comments](/api/runtime-api/module-methods#magic-comments) support for CommonJS.
173+
174+
```js title="rspack.config.mjs"
175+
export default {
176+
module: {
177+
parser: {
178+
javascript: {
179+
commonjsMagicComments: true,
180+
},
181+
},
182+
},
183+
};
184+
```
185+
186+
Note that only `webpackIgnore` comment is supported at the moment:
187+
188+
```js
189+
const x = require(/* webpackIgnore: true */ 'x');
190+
```
191+
167192
### module.parser.javascript.dynamicImportMode
168193
169194
<PropertyType

website/docs/zh/config/module.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,31 @@ export default {
164164
};
165165
```
166166
167+
### module.parser.javascript.commonjsMagicComments
168+
169+
<PropertyType type="boolean" defaultValueList={[{ defaultValue: 'false' }]} />
170+
<ApiMeta addedVersion="1.5.6" />
171+
172+
为 CommonJS 启用 [Magic comments](/api/runtime-api/module-methods#magic-comments) 支持。
173+
174+
```js title="rspack.config.mjs"
175+
export default {
176+
module: {
177+
parser: {
178+
javascript: {
179+
commonjsMagicComments: true,
180+
},
181+
},
182+
},
183+
};
184+
```
185+
186+
目前仅支持 `webpackIgnore` 注释:
187+
188+
```js
189+
const x = require(/* webpackIgnore: true */ 'x');
190+
```
191+
167192
### module.parser.javascript.dynamicImportMode
168193
169194
<PropertyType

0 commit comments

Comments
 (0)