Skip to content

Latest commit

 

History

History

dev-middleware

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

devMiddleware option

Provide options to webpack-dev-middleware which handles webpack assets.

webpack.config.js

module.exports = {
  // ...
  devServer: {
    devMiddleware: {
      index: true,
      headers: {
        "X-Custom-Header": "yes",
      },
    },
  },
};

To run this example use the following command:

npx webpack serve --open

What should happen

  1. The script should open http://localhost:8080/.
  2. You should see the text on the page itself change to read Success!.
  3. Open the console in your browser's devtools and select the Network tab.
  4. Find main.js. The response headers should contain X-Custom-Header: yes.

Now update webpack.config.js with index: false, this will tell the server to not respond to requests to the root URL.

Now close and restart the server with:

npx webpack serve --open

What should happen

  1. The script should open http://localhost:8080/.
  2. You should see the Cannot GET / text on the page.