Skip to content

Commit b14bd1d

Browse files
billy-leEugeneHlushko
authored andcommitted
docs(configuration): add onListening, update after and before in devServer (#3317)
* content-dev-server: add onListening and update after and before functions * content-dev-server: updated onListening example and description
1 parent 0725c91 commit b14bd1d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/content/configuration/dev-server.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ T> HTML template is required to serve the bundle, usually it is an `index.html`
6464

6565
## `devServer.after`
6666

67-
`function (app, server)`
67+
`function (app, server, compiler)`
6868

6969
Provides the ability to execute custom middleware after all other middleware
7070
internally within the server.
@@ -75,7 +75,7 @@ __webpack.config.js__
7575
module.exports = {
7676
//...
7777
devServer: {
78-
after: function(app, server) {
78+
after: function(app, server, compiler) {
7979
// do fancy stuff
8080
}
8181
}
@@ -131,7 +131,7 @@ webpack-dev-server --entry /entry/file --output-path /output/path --allowed-host
131131

132132
## `devServer.before`
133133

134-
`function (app, server)`
134+
`function (app, server, compiler)`
135135

136136
Provides the ability to execute custom middleware prior to all other middleware
137137
internally within the server. This could be used to define custom handlers, for
@@ -143,7 +143,7 @@ __webpack.config.js__
143143
module.exports = {
144144
//...
145145
devServer: {
146-
before: function(app, server) {
146+
before: function(app, server, compiler) {
147147
app.get('/some/path', function(req, res) {
148148
res.json({ custom: 'response' });
149149
});
@@ -763,6 +763,25 @@ module.exports = {
763763
};
764764
```
765765

766+
## `devServer.onListening`
767+
768+
`function (server)`
769+
770+
Provides an option to execute a custom function when `webpack-dev-server` starts listening for connections on a port.
771+
772+
__webpack.config.js__
773+
774+
```javascript
775+
module.exports = {
776+
//...
777+
devServer: {
778+
onListening: function(server) {
779+
const port = server.listeningApp.address().port;
780+
console.log('Listening on port:', port);
781+
}
782+
}
783+
};
784+
```
766785

767786
## `devServer.open`
768787

0 commit comments

Comments
 (0)