Adds headers to all responses.
webpack.config.js
module.exports = {
// ...
devServer: {
headers: () => {
return { "X-Custom-Header": ["key1=value1", "key2=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-Custom-Header: key1=value1
andX-Custom-Header: key2=value2
.