Skip to content

Commit 6869880

Browse files
committed
feat: support for glob support
1 parent e65904a commit 6869880

9 files changed

Lines changed: 116 additions & 160 deletions

File tree

lib/Server.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3188,8 +3188,16 @@ class Server {
31883188
*/
31893189
watchFiles(watchPath, watchOptions = {}) {
31903190
const chokidar = require("chokidar");
3191+
const { globSync, isDynamicPattern } = require("tinyglobby");
31913192

3192-
const watcher = chokidar.watch(watchPath, watchOptions);
3193+
const paths = Array.isArray(watchPath) ? watchPath : [watchPath];
3194+
const resolvedPaths = paths.flatMap((path) =>
3195+
isDynamicPattern(path)
3196+
? globSync(path, { cwd: watchOptions.cwd, absolute: true })
3197+
: path,
3198+
);
3199+
3200+
const watcher = chokidar.watch(resolvedPaths, watchOptions);
31933201

31943202
// disabling refreshing on changing the content
31953203
if (this.options.liveReload) {

lib/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@
850850
"$ref": "#/definitions/WatchFilesObject"
851851
}
852852
],
853-
"description": "Allows to configure list of directories/files to watch for file changes.",
853+
"description": "Allows to configure list of globs/directories/files to watch for file changes.",
854854
"link": "https://webpack.js.org/configuration/dev-server/#devserverwatchfiles"
855855
},
856856
"WatchFilesObject": {
@@ -873,7 +873,7 @@
873873
"minLength": 1
874874
}
875875
],
876-
"description": "Path(s) of directories/files to watch for file changes."
876+
"description": "Path(s) of globs/directories/files to watch for file changes."
877877
},
878878
"options": {
879879
"type": "object",

migration-v6.md

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,6 @@ This document serves as a migration guide for `webpack-dev-server@6.0.0`.
3737
};
3838
```
3939

40-
- Updated `chokidar` from v3 to v4. Glob patterns are no longer supported in `watchFiles`. If you previously used globs, you can watch a directory and filter with `ignored`:
41-
42-
v5:
43-
44-
```js
45-
module.exports = {
46-
devServer: {
47-
watchFiles: "src/**/*.js",
48-
},
49-
};
50-
```
51-
52-
v6:
53-
54-
```js
55-
module.exports = {
56-
devServer: {
57-
watchFiles: {
58-
paths: "src",
59-
options: {
60-
ignored: (path, stats) => stats?.isFile() && !path.endsWith(".js"),
61-
},
62-
},
63-
},
64-
};
65-
```
66-
67-
Or resolve the glob before passing it:
68-
69-
```js
70-
const { globSync } = require("node:fs");
71-
72-
module.exports = {
73-
devServer: {
74-
watchFiles: globSync("src/**/*.js"),
75-
},
76-
};
77-
```
78-
79-
> **Note:** `fs.globSync` requires Node.js 22+. For Node.js 20, use a package like `fast-glob` or `tinyglobby`.
80-
8140
- Now, webpack-dev-server adds WebSocket communication only when the `target` is set to a web-compatible environment. Previously, it also injected WebSocket communication if `resolve` contained a `conditionNames` entry with `browser` or if `externalsPresets.web` existed.
8241

8342
- When retrieving the configuration in a multi-compiler setup, it will look for one that has a target compatible with a web environment. If it doesn’t find one, it will fall back to the first compiler found by webpack.

package-lock.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"schema-utils": "^4.3.3",
6767
"selfsigned": "^5.5.0",
6868
"serve-index": "^1.9.2",
69+
"tinyglobby": "^0.2.15",
6970
"webpack-dev-middleware": "^8.0.2",
7071
"ws": "^8.20.0"
7172
},
@@ -85,6 +86,7 @@
8586
"@types/graceful-fs": "^4.1.9",
8687
"@types/node": "^24.0.14",
8788
"@types/node-forge": "^1.3.1",
89+
"@types/picomatch": "^4.0.2",
8890
"@types/trusted-types": "^2.0.7",
8991
"acorn": "^8.14.0",
9092
"babel-jest": "^30.0.4",

0 commit comments

Comments
 (0)