Adds headers to all responses.
webpack.config.js
module.exports = {
// ...
devServer: {
headers: [
{
key: "X-Foo",
value: "value1",
},
{
key: "X-Bar",
value: "value2",
},
],
},
};
To run this example use the following command:
npx webpack serve --open
- The script should open
http://localhost:8080/
. - You should see the text on the page itself change to read
Success!
. - Open the console in your browser's devtools and select the Network tab.
- Find
main.js
. The response headers should containX-Foo: value1
andX-Bar: value2
.