webpack Development server: webpack-dev-server Installation


Example

webpack-dev-server can be installed via npm

npm --save-dev webpack-dev-server

now you can start server

./node_modules/.bin/webpack-dev-server

To simplify usage you can add script to package.json

// package.json
{
  ...
  "scripts": {
    "start": "webpack-dev-server"
  },
  ...
}

now to run server you can use

npm run start

webpack-dev-server is configured in webpack.config.js file in section devServer.

To change server content base directory you can use option contentBase. Example configuration setting root directory to public_html could look like

let path = require("path");

module.exports = {
  ...
  devServer: {
    contentBase: path.resolve(__dirname, "public_html")
  },
  ...
}