Installing webpack
This guide covers how to install webpack in your project.Prerequisites
webpack requires Node.js version 10.13.0 or higher. Check your Node.js version with
node -v.- Node.js installed (version 10.13.0 or higher)
- npm, yarn, or pnpm package manager
Local Installation (Recommended)
For most projects, we recommend installing webpack locally. This allows different projects to use different versions of webpack and makes your build reproducible.Install webpack and webpack-cli
Choose your preferred package manager:
webpack-cli is optional but recommended. It provides a command-line interface for running webpack and accessing helpful commands.Global Installation
If you need webpack available globally (for quick experiments or testing):webpack directly from your terminal.
Version-Specific Installation
To install a specific version of webpack:Installing Loaders and Plugins
Webpack’s power comes from its ecosystem of loaders and plugins. Install them as dev dependencies:Bleeding Edge Installation
To install the latest development version directly from the repository:Verifying Your Installation
After installation, verify everything is set up correctly:-
Check webpack version:
-
Check webpack-cli version:
-
View webpack help:
Package Scripts
Add webpack to yourpackage.json scripts for easier access:
package.json