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-server
package is responsible to serve the build over anhttp
server that it creates for it. It also re-starts if you make any changes to the source code (when using thehot
reload option).On the other hand, the
webpack-cli
package is responsible for the build and bundle of the source files. So,webpack-dev-server
has 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
webpack
v5, that order kind of got reversed since you usewebpack server
, which is awebpack-cli
call, to initiate the serve, that will call thewebpack-dev-server
package.I'm not a
webpack
expert by any means, but I think this will help you to understand it better.