webpack-cli is the official command-line interface for webpack, a widely adopted module bundler for modern JavaScript applications. It provides a robust set of commands and options to streamline the configuration and execution of webpack builds. Currently stable at version 7.0.2, it receives regular patch releases, with major version updates often coinciding with Node.js LTS cycles or significant shifts in the webpack ecosystem. A key differentiator is its ability to simplify the initialization and management of complex webpack configurations, offering a flexible approach to project setup that works both with and without a pre-existing `webpack.config.js` file. It consolidates common development tasks such as building, serving with a dev server, and watching for file changes, significantly enhancing developer productivity within the webpack environment.
npm install webpack-cliVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic webpack build using `webpack-cli` with a simple ES module configuration, including how to pass environment variables.
Upgrade your Node.js environment to version 20.9.0 or newer. Use `nvm install 20 && nvm use 20` or your preferred Node.js version manager.
For new projects or scaffolding, use `npx create-webpack-app` instead. If you need to migrate existing scripts, adapt them to manually configure webpack or use `create-webpack-app`'s functionality.
Update your `webpack-dev-server` dependency to `^5.0.0` or later in your `package.json`.
Ensure your `webpack` dependency is updated to `^5.82.0` or newer in your `package.json`.
Update your CLI commands or scripts to use `--config-node-env` instead of the old option name.
For optimal compatibility and to utilize modern Node.js features, consider migrating your `webpack.config.js` to an ES module format (e.g., using `export default { ... }`) or naming it `webpack.config.mjs`. If sticking with CJS, ensure it's compatible with potential dynamic import fallbacks or use `--disable-interpret` if encountering issues.Install webpack: `npm install --save-dev webpack` or `yarn add webpack --dev`.
Use `npx create-webpack-app` for scaffolding new webpack projects or migrating existing ones. Consult the `webpack-cli` documentation for alternative commands.
Upgrade your Node.js to version 20.9.0 or newer. Recommended: `nvm install 20 && nvm use 20`.
Install the correct version: `npm install --save-dev webpack-dev-server@^5.0.0` or `yarn add webpack-dev-server@^5.0.0 --dev`.