Skip to content

Commit dfe9c47

Browse files
EugeneHlushkomontogeek
authored andcommitted
docs(config) Small improvements to configuration watch page (#2751)
- general tidy up for examples - types defaults are now consistent - provided extra links for dev-server and dev-midlwr [1]: https://cla.js.foundation/webpack/webpack.js.org [2]: https://webpack.js.org/writers-guide/
1 parent e2bc108 commit dfe9c47

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

src/content/configuration/watch.md

+28-16
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ webpack can watch files and recompile whenever they change. This page explains h
1515

1616
## `watch`
1717

18-
`boolean`
18+
`boolean: false`
1919

20-
Turn on watch mode. This means that after the initial build, webpack will continue to watch for changes in any of the resolved files. Watch mode is turned off by default:
20+
Turn on watch mode. This means that after the initial build, webpack will continue to watch for changes in any of the resolved files.
2121

22-
```js
22+
__webpack.config.js__
23+
24+
```javascript
2325
module.exports = {
2426
//...
25-
watch: false
27+
watch: true
2628
};
2729
```
2830

29-
T> In webpack-dev-server and webpack-dev-middleware watch mode is enabled by default.
31+
T> In [webpack-dev-server](https://github.com/webpack/webpack-dev-server) and [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) watch mode is enabled by default.
3032

3133

3234
## `watchOptions`
@@ -35,7 +37,9 @@ T> In webpack-dev-server and webpack-dev-middleware watch mode is enabled by def
3537

3638
A set of options used to customize watch mode:
3739

38-
```js
40+
__webpack.config.js__
41+
42+
```javascript
3943
module.exports = {
4044
//...
4145
watchOptions: {
@@ -48,25 +52,29 @@ module.exports = {
4852

4953
## `watchOptions.aggregateTimeout`
5054

51-
`number`
55+
`number: 300`
5256

5357
Add a delay before rebuilding once the first file changed. This allows webpack to aggregate any other changes made during this time period into one rebuild. Pass a value in milliseconds:
5458

55-
```js
59+
```javascript
5660
module.exports = {
5761
//...
5862
watchOptions: {
59-
aggregateTimeout: 300 // The default
63+
aggregateTimeout: 600
6064
}
6165
};
6266
```
6367

6468

6569
## `watchOptions.ignored`
6670

71+
`RegExp` [`anymatch`](https://github.com/micromatch/anymatch)
72+
6773
For some systems, watching many file systems can result in a lot of CPU or memory usage. It is possible to exclude a huge folder like `node_modules`:
6874

69-
```js
75+
__webpack.config.js__
76+
77+
```javascript
7078
module.exports = {
7179
//...
7280
watchOptions: {
@@ -77,7 +85,9 @@ module.exports = {
7785

7886
It is also possible to have and use multiple [anymatch](https://github.com/micromatch/anymatch) patterns:
7987

80-
```js
88+
__webpack.config.js__
89+
90+
```javascript
8191
module.exports = {
8292
//...
8393
watchOptions: {
@@ -91,11 +101,13 @@ T> If you use `require.context`, webpack will watch your entire directory. You w
91101

92102
## `watchOptions.poll`
93103

94-
`boolean` `number`
104+
`boolean: false` `number`
95105

96106
Turn on [polling](https://whatis.techtarget.com/definition/polling) by passing `true`, or specifying a poll interval in milliseconds:
97107

98-
```js
108+
__webpack.config.js__
109+
110+
```javascript
99111
module.exports = {
100112
//...
101113
watchOptions: {
@@ -109,7 +121,7 @@ T> If watching does not work for you, try out this option. Watching does not wor
109121

110122
## `info-verbosity`
111123

112-
`string`: `none` `info` `verbose`
124+
`string: 'none', 'info', 'verbose'`
113125

114126
Controls verbosity of the lifecycle messaging, e.g. the `Started watching files...` log. Setting `info-verbosity` to `verbose` will also message to console at the beginning and the end of incremental build. `info-verbosity` is set to `info` by default.
115127

@@ -146,9 +158,9 @@ On macOS, folders can get corrupted in certain scenarios. See [this article](htt
146158

147159
### Windows Paths
148160

149-
Because webpack expects absolute paths for many config options such as `__dirname + "/app/folder"` the Windows `\` path separator can break some functionality.
161+
Because webpack expects absolute paths for many config options such as `__dirname + '/app/folder'` the Windows `\` path separator can break some functionality.
150162

151-
Use the correct separators. I.e. `path.resolve(__dirname, "app/folder")` or `path.join(__dirname, "app", "folder")`.
163+
Use the correct separators. I.e. `path.resolve(__dirname, 'app/folder')` or `path.join(__dirname, 'app', 'folder')`.
152164

153165
### Vim
154166

0 commit comments

Comments
 (0)