How is webpack-cli used in a project?
From what I understand, as soon as I enter npm run start on my bash terminal, webpack starts running the webpack config file where I have written rules to convert jsx to js using babel, scss/less to css (correct me if I'm wrong).
But where does webpack-cli comes into play in all this?
The
webpack-dev-serverpackage is responsible to serve the build over anhttpserver that it creates for it. It also re-starts if you make any changes to the source code (when using thehotreload option).On the other hand, the
webpack-clipackage is responsible for the build and bundle of the source files. So,webpack-dev-serverhas to run thewebpack-cli.So you've got to have both of the packages installed.
You can see kind of how it does that in here:
https://github.com/webpack/webpack-dev-server/blob/master/bin/webpack-dev-server.js
In
webpackv5, that order kind of got reversed since you usewebpack server, which is awebpack-clicall, to initiate the serve, that will call thewebpack-dev-serverpackage.I'm not a
webpackexpert by any means, but I think this will help you to understand it better.