File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ # onListening
2
+
3
+ Provides the ability to execute a custom function when webpack-dev-server starts listening for connections on a port.
4
+
5
+ ** webpack.config.js**
6
+
7
+ ``` js
8
+ module .exports = {
9
+ // ...
10
+ devServer: {
11
+ onListening : (devServer ) => {
12
+ const port = devServer .server .address ().port ;
13
+ console .log (" Listening on port:" , port);
14
+ },
15
+ },
16
+ };
17
+ ```
18
+
19
+ To run this example use the following command:
20
+
21
+ ``` console
22
+ npx webpack serve --open
23
+ ```
24
+
25
+ ## What Should Happen
26
+
27
+ 1 . The script should open ` https://localhost:8080/ ` in your default browser.
28
+ 2 . You should see the text on the page itself change to read ` Success! ` .
29
+ 3 . Check the terminal output, you should see ` Listening on port: 8080 ` in the output.
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ const target = document . querySelector ( "#target" ) ;
4
+
5
+ target . classList . add ( "pass" ) ;
6
+ target . innerHTML = "Success!" ;
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ // our setup function adds behind-the-scenes bits to the config that all of our
4
+ // examples need
5
+ const { setup } = require ( "../util" ) ;
6
+
7
+ module . exports = setup ( {
8
+ context : __dirname ,
9
+ entry : "./app.js" ,
10
+ devServer : {
11
+ onListening : ( devServer ) => {
12
+ const port = devServer . server . address ( ) . port ;
13
+ console . log ( "Listening on port:" , port ) ;
14
+ } ,
15
+ } ,
16
+ } ) ;
You can’t perform that action at this time.
0 commit comments