Skip to content

Commit 9c040c1

Browse files
EugeneHlushkomontogeek
authored andcommitted
docs(config) Update configuration module page (#2576)
1 parent 24f8c40 commit 9c040c1

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

src/content/configuration/module.md

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,50 @@ contributors:
1111
- pnevares
1212
- fadysamirsadek
1313
- nerdkid93
14+
- EugeneHlushko
1415
---
1516

1617
These options determine how the [different types of modules](/concepts/modules) within a project will be treated.
1718

1819

1920
## `module.noParse`
2021

21-
`RegExp | [RegExp]`
22+
`RegExp | [RegExp] | function | string | [string]`
2223

23-
`RegExp | [RegExp] | function` (since webpack 3.0.0)
24+
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.
2425

25-
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.
26+
__webpack.config.js__
2627

27-
```js
28+
```javascript
2829
module.exports = {
2930
//...
3031
module: {
3132
noParse: /jquery|lodash/,
33+
}
34+
};
35+
```
3236

33-
// since webpack 3.0.0
34-
noParse: function(content) {
35-
return /jquery|lodash/.test(content);
36-
}
37+
```javascript
38+
module.exports = {
39+
//...
40+
module: {
41+
noParse: (content) => /jquery|lodash/.test(content)
3742
}
3843
};
3944
```
4045

46+
4147
## `module.rules`
4248

43-
`array`
49+
`[Rule]`
4450

4551
An array of [Rules](#rule) which are matched to requests when modules are created. These rules can modify how the module is created. They can apply loaders to the module, or modify the parser.
4652

4753

4854
## Rule
4955

56+
`object`
57+
5058
A Rule can be separated into three parts — Conditions, Results and nested Rules.
5159

5260

@@ -58,7 +66,7 @@ There are two input values for the conditions:
5866

5967
2. The issuer: An absolute path to the file of the module which requested the resource. It's the location of the import.
6068

61-
**Example:** When we `import './style.css'` within `app.js`, the resource is `/path/to/style.css` and the issuer is `/path/to/app.js`.
69+
__Example:__ When we `import './style.css'` within `app.js`, the resource is `/path/to/style.css` and the issuer is `/path/to/app.js`.
6270

6371
In a Rule the properties [`test`](#rule-test), [`include`](#rule-include), [`exclude`](#rule-exclude) and [`resource`](#rule-resource) are matched with the resource and the property [`issuer`](#rule-issuer) is matched with the issuer.
6472

@@ -94,7 +102,9 @@ These rules are evaluated when the Rule condition matches.
94102

95103
## `Rule.enforce`
96104

97-
Possible values: `"pre" | "post"`
105+
`string`
106+
107+
Possible values: `'pre' | 'post'`
98108

99109
Specifies the category of the loader. No value means normal loader.
100110

@@ -130,7 +140,7 @@ A [`Condition`](#condition) to match against the module that issued the request.
130140

131141
__index.js__
132142

133-
```js
143+
```javascript
134144
import A from './a.js';
135145
```
136146

@@ -153,6 +163,8 @@ W> This option is __deprecated__ in favor of `Rule.use`.
153163

154164
An array of [`Rules`](#rule) from which only the first matching Rule is used when the Rule matches.
155165

166+
__webpack.config.js__
167+
156168
```javascript
157169
module.exports = {
158170
//...
@@ -189,12 +201,12 @@ An object with parser options. All applied parser options are merged.
189201

190202
Parsers may inspect these options and disable or reconfigure themselves accordingly. Most of the default plugins interpret the values as follows:
191203

192-
* Setting the option to `false` disables the parser.
193-
* Setting the option to `true` or leaving it `undefined` enables the parser.
204+
- Setting the option to `false` disables the parser.
205+
- Setting the option to `true` or leaving it `undefined` enables the parser.
194206

195207
However, parser plugins may accept more than just a boolean. For example, the internal `NodeStuffPlugin` can accept an object instead of `true` to add additional options for a particular Rule.
196208

197-
**Examples** (parser options by the default plugins):
209+
__Examples__ (parser options by the default plugins):
198210

199211
```js-with-links
200212
module.exports = {
@@ -232,7 +244,9 @@ A [`Condition`](#condition) matched with the resource. You can either supply a `
232244

233245
A [`Condition`](#condition) matched with the resource query. This option is used to test against the query section of a request string (i.e. from the question mark onwards). If you were to `import Foo from './foo.css?inline'`, the following condition would match:
234246

235-
```js
247+
__webpack.config.js__
248+
249+
```javascript
236250
module.exports = {
237251
//...
238252
module: {
@@ -255,7 +269,7 @@ An array of [`Rules`](#rule) that is also used when the Rule matches.
255269

256270
## `Rule.sideEffects`
257271

258-
Possible values: `true | false`
272+
`bool`
259273

260274
Indicate what parts of the module contain side effects. See [Tree Shaking](/guides/tree-shaking/#mark-the-file-as-side-effect-free) for details.
261275

@@ -267,10 +281,14 @@ Indicate what parts of the module contain side effects. See [Tree Shaking](/guid
267281

268282
## `Rule.type`
269283

270-
Possible values: `"javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/experimental"`
284+
`string`
285+
286+
Possible values: `'javascript/auto' | 'javascript/dynamic' | 'javascript/esm' | 'json' | 'webassembly/experimental'`
271287

272288
`Rule.type` sets the type for a matching module. This prevents defaultRules and their default importing behaviors from occurring. For example, if you want to load a `.json` file through a custom loader, you'd need to set the `type` to `javascript/auto` to bypass webpack's built-in json importing. (See [v4.0 changelog](https://github.com/webpack/webpack/releases/tag/v4.0.0) for more details)
273289

290+
__webpack.config.js__
291+
274292
```javascript
275293
module.exports = {
276294
//...
@@ -292,10 +310,12 @@ module.exports = {
292310

293311
A list of [UseEntries](#useentry) which are applied to modules. Each entry specifies a loader to be used.
294312

295-
Passing a string (i.e. `use: [ "style-loader" ]`) is a shortcut to the loader property (i.e. `use: [ { loader: "style-loader "} ]`).
313+
Passing a string (i.e. `use: [ 'style-loader' ]`) is a shortcut to the loader property (i.e. `use: [ { loader: 'style-loader '} ]`).
296314

297315
Loaders can be chained by passing multiple loaders, which will be applied from right to left (last to first configured).
298316

317+
__webpack.config.js__
318+
299319
```javascript
300320
module.exports = {
301321
//...
@@ -331,11 +351,11 @@ See [UseEntry](#useentry) for details.
331351

332352
Conditions can be one of these:
333353

334-
* A string: To match the input must start with the provided string. I. e. an absolute directory path, or absolute path to the file.
335-
* A RegExp: It's tested with the input.
336-
* A function: It's called with the input and must return a truthy value to match.
337-
* An array of Conditions: At least one of the Conditions must match.
338-
* An object: All properties must match. Each property has a defined behavior.
354+
- A string: To match the input must start with the provided string. I. e. an absolute directory path, or absolute path to the file.
355+
- A RegExp: It's tested with the input.
356+
- A function: It's called with the input and must return a truthy value to match.
357+
- An array of Conditions: At least one of the Conditions must match.
358+
- An object: All properties must match. Each property has a defined behavior.
339359

340360
`{ test: Condition }`: The Condition must match. The convention is to provide a RegExp or array of RegExps here, but it's not enforced.
341361

@@ -349,9 +369,9 @@ Conditions can be one of these:
349369

350370
`{ not: [Condition] }`: All Conditions must NOT match.
351371

352-
**Example:**
372+
__Example:__
353373

354-
```js
374+
```javascript
355375
module.exports = {
356376
//...
357377
module: {
@@ -379,9 +399,9 @@ It can have an `options` property being a string or object. This value is passed
379399

380400
For compatibility a `query` property is also possible, which is an alias for the `options` property. Use the `options` property instead.
381401

382-
**Example:**
402+
__webpack.config.js__
383403

384-
```js
404+
```javascript
385405
module.exports = {
386406
//...
387407
module: {
@@ -412,11 +432,13 @@ Example for an `unknown` dynamic dependency: `require`.
412432

413433
Example for an `expr` dynamic dependency: `require(expr)`.
414434

415-
Example for an `wrapped` dynamic dependency: `require("./templates/" + expr)`.
435+
Example for an `wrapped` dynamic dependency: `require('./templates/' + expr)`.
416436

417437
Here are the available options with their [defaults](https://github.com/webpack/webpack/blob/master/lib/WebpackOptionsDefaulter.js):
418438

419-
```js
439+
__webpack.config.js__
440+
441+
```javascript
420442
module.exports = {
421443
//...
422444
module: {
@@ -440,7 +462,7 @@ T> You can use the `ContextReplacementPlugin` to modify these values for individ
440462

441463
A few use cases:
442464

443-
* Warn for dynamic dependencies: `wrappedContextCritical: true`.
444-
* `require(expr)` should include the whole directory: `exprContextRegExp: /^\.\//`
445-
* `require("./templates/" + expr)` should not include subdirectories by default: `wrappedContextRecursive: false`
446-
* `strictExportPresence` makes missing exports an error instead of warning
465+
- Warn for dynamic dependencies: `wrappedContextCritical: true`.
466+
- `require(expr)` should include the whole directory: `exprContextRegExp: /^\.\//`
467+
- `require('./templates/' + expr)` should not include subdirectories by default: `wrappedContextRecursive: false`
468+
- `strictExportPresence` makes missing exports an error instead of warning

0 commit comments

Comments
 (0)