File tree Expand file tree Collapse file tree 6 files changed +100
-0
lines changed Expand file tree Collapse file tree 6 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ # headers option as a function
2
+
3
+ Adds headers to all responses.
4
+
5
+ ** webpack.config.js**
6
+
7
+ ``` js
8
+ module .exports = {
9
+ // ...
10
+ devServer: {
11
+ headers : () => {
12
+ return { " X-Custom-Header" : [" key1=value1" , " key2=value2" ] };
13
+ },
14
+ },
15
+ };
16
+ ```
17
+
18
+ To run this example use the following command:
19
+
20
+ ``` console
21
+ npx webpack serve --open
22
+ ```
23
+
24
+ ## What should happen
25
+
26
+ 1 . The script should open ` http://localhost:8080/ ` .
27
+ 2 . You should see the text on the page itself change to read ` Success! ` .
28
+ 3 . Open the console in your browser's devtools and select the _ Network_ tab.
29
+ 4 . Find ` main.js ` . The response headers should contain ` X-Custom-Header: key1=value1 ` and ` X-Custom-Header: key2=value2 ` .
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
+ headers : ( ) => {
12
+ return { "X-Custom-Header" : [ "key1=value1" , "key2=value2" ] } ;
13
+ } ,
14
+ } ,
15
+ } ) ;
Original file line number Diff line number Diff line change
1
+ # headers option as an object
2
+
3
+ Adds headers to all responses.
4
+
5
+ ** webpack.config.js**
6
+
7
+ ``` js
8
+ module .exports = {
9
+ // ...
10
+ devServer: {
11
+ headers: {
12
+ " X-Custom-Header" : " yes" ,
13
+ },
14
+ },
15
+ };
16
+ ```
17
+
18
+ To run this example use the following command:
19
+
20
+ ``` console
21
+ npx webpack serve --open
22
+ ```
23
+
24
+ ## What should happen
25
+
26
+ 1 . The script should open ` http://localhost:8080/ ` .
27
+ 2 . You should see the text on the page itself change to read ` Success! ` .
28
+ 3 . Open the console in your browser's devtools and select the _ Network_ tab.
29
+ 4 . Find ` main.js ` . The response headers should contain ` X-Custom-Header: yes ` .
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
+ headers : {
12
+ "X-Custom-Header" : "yes" ,
13
+ } ,
14
+ } ,
15
+ } ) ;
You can’t perform that action at this time.
0 commit comments