Skip to content

Commit 87756b9

Browse files
authored
docs(configuration): update module.noParse (#7205)
1 parent 2b1eb96 commit 87756b9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/content/configuration/module.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,18 @@ The `'relative'` value for `module.parser.javascript.url` is available since web
533533

534534
Prevent webpack from parsing any files matching the given regular expression(s). Ignored files **should not** have calls to `import`, `require`, `define` or any other importing mechanism. This can boost build performance when ignoring large libraries.
535535

536+
`noParse` can be also used as a way to deliberately prevent expansion of all `import`, `require`, `define` etc. calls for cases when those calls are unreachable at runtime.
537+
For example, when building a project for `'browser'` [target](/configuration/target/) and using a third-party library that was prebuilt for both browser and Node.js and it requires Node.js built-ins e.g. `require('os')`.
538+
539+
T> You may need to use `[\\/]` in regex to match `\` on Windows and `/` on Mac/Linux.
540+
536541
**webpack.config.js**
537542

538543
```javascript
539544
module.exports = {
540545
//...
541546
module: {
542-
noParse: /jquery|lodash/,
547+
noParse: /jquery|lodash|src[\\/]vendor[\\/]somelib/,
543548
},
544549
};
545550
```
@@ -548,7 +553,8 @@ module.exports = {
548553
module.exports = {
549554
//...
550555
module: {
551-
noParse: (content) => /jquery|lodash/.test(content),
556+
noParse: (content) =>
557+
/jquery|lodash|src[\\/]vendor[\\/]somelib/.test(content),
552558
},
553559
};
554560
```

0 commit comments

Comments
 (0)