You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
24
25
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.
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.
46
52
47
53
48
54
## Rule
49
55
56
+
`object`
57
+
50
58
A Rule can be separated into three parts — Conditions, Results and nested Rules.
51
59
52
60
@@ -58,7 +66,7 @@ There are two input values for the conditions:
58
66
59
67
2. The issuer: An absolute path to the file of the module which requested the resource. It's the location of the import.
60
68
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`.
62
70
63
71
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.
64
72
@@ -94,7 +102,9 @@ These rules are evaluated when the Rule condition matches.
94
102
95
103
## `Rule.enforce`
96
104
97
-
Possible values: `"pre" | "post"`
105
+
`string`
106
+
107
+
Possible values: `'pre' | 'post'`
98
108
99
109
Specifies the category of the loader. No value means normal loader.
100
110
@@ -130,7 +140,7 @@ A [`Condition`](#condition) to match against the module that issued the request.
130
140
131
141
__index.js__
132
142
133
-
```js
143
+
```javascript
134
144
importAfrom'./a.js';
135
145
```
136
146
@@ -153,6 +163,8 @@ W> This option is __deprecated__ in favor of `Rule.use`.
153
163
154
164
An array of [`Rules`](#rule) from which only the first matching Rule is used when the Rule matches.
155
165
166
+
__webpack.config.js__
167
+
156
168
```javascript
157
169
module.exports= {
158
170
//...
@@ -189,12 +201,12 @@ An object with parser options. All applied parser options are merged.
189
201
190
202
Parsers may inspect these options and disable or reconfigure themselves accordingly. Most of the default plugins interpret the values as follows:
191
203
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.
194
206
195
207
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.
196
208
197
-
**Examples** (parser options by the default plugins):
209
+
__Examples__ (parser options by the default plugins):
198
210
199
211
```js-with-links
200
212
module.exports = {
@@ -232,7 +244,9 @@ A [`Condition`](#condition) matched with the resource. You can either supply a `
232
244
233
245
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:
234
246
235
-
```js
247
+
__webpack.config.js__
248
+
249
+
```javascript
236
250
module.exports= {
237
251
//...
238
252
module: {
@@ -255,7 +269,7 @@ An array of [`Rules`](#rule) that is also used when the Rule matches.
255
269
256
270
## `Rule.sideEffects`
257
271
258
-
Possible values: `true | false`
272
+
`bool`
259
273
260
274
Indicate what parts of the module contain side effects. See [Tree Shaking](/guides/tree-shaking/#mark-the-file-as-side-effect-free) for details.
261
275
@@ -267,10 +281,14 @@ Indicate what parts of the module contain side effects. See [Tree Shaking](/guid
`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)
273
289
290
+
__webpack.config.js__
291
+
274
292
```javascript
275
293
module.exports= {
276
294
//...
@@ -292,10 +310,12 @@ module.exports = {
292
310
293
311
A list of [UseEntries](#useentry) which are applied to modules. Each entry specifies a loader to be used.
294
312
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 '} ]`).
296
314
297
315
Loaders can be chained by passing multiple loaders, which will be applied from right to left (last to first configured).
298
316
317
+
__webpack.config.js__
318
+
299
319
```javascript
300
320
module.exports= {
301
321
//...
@@ -331,11 +351,11 @@ See [UseEntry](#useentry) for details.
331
351
332
352
Conditions can be one of these:
333
353
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.
339
359
340
360
`{ test: Condition }`: The Condition must match. The convention is to provide a RegExp or array of RegExps here, but it's not enforced.
341
361
@@ -349,9 +369,9 @@ Conditions can be one of these:
349
369
350
370
`{ not: [Condition] }`: All Conditions must NOT match.
351
371
352
-
**Example:**
372
+
__Example:__
353
373
354
-
```js
374
+
```javascript
355
375
module.exports= {
356
376
//...
357
377
module: {
@@ -379,9 +399,9 @@ It can have an `options` property being a string or object. This value is passed
379
399
380
400
For compatibility a `query` property is also possible, which is an alias for the `options` property. Use the `options` property instead.
381
401
382
-
**Example:**
402
+
__webpack.config.js__
383
403
384
-
```js
404
+
```javascript
385
405
module.exports= {
386
406
//...
387
407
module: {
@@ -412,11 +432,13 @@ Example for an `unknown` dynamic dependency: `require`.
412
432
413
433
Example for an `expr` dynamic dependency: `require(expr)`.
414
434
415
-
Example for an `wrapped` dynamic dependency: `require("./templates/" + expr)`.
435
+
Example for an `wrapped` dynamic dependency: `require('./templates/' + expr)`.
416
436
417
437
Here are the available options with their [defaults](https://github.com/webpack/webpack/blob/master/lib/WebpackOptionsDefaulter.js):
418
438
419
-
```js
439
+
__webpack.config.js__
440
+
441
+
```javascript
420
442
module.exports= {
421
443
//...
422
444
module: {
@@ -440,7 +462,7 @@ T> You can use the `ContextReplacementPlugin` to modify these values for individ
440
462
441
463
A few use cases:
442
464
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