This guide covers the various methods used to install webpack.
Before you begin, make sure you have a recent version of Node.js installed. The current Long Term Support (LTS) release is an ideal starting point. Older versions may cause a variety of issues, since they can lack functionality that webpack and its related packages depend on.
The latest webpack release is:
To install the latest release or a specific version, run one of the following commands:
npm install --save-dev webpack
# or a specific version
npm install --save-dev webpack@<version>[!TIP] Whether to use
--save-devdepends on your use case. If you use webpack only for bundling, installing it with--save-devis recommended, since you won't include webpack in your production build. Otherwise, you can omit--save-dev.
If you're using webpack v4 or later and want to call webpack from the command line, you'll also need to install the CLI:
npm install --save-dev webpack-cliInstalling locally is what we recommend for most projects. It makes it easier to upgrade projects individually when breaking changes are introduced. Typically, webpack is run through one or more npm scripts that look for a webpack installation in your local node_modules directory:
"scripts": {
"build": "webpack --config webpack.config.js"
}[!TIP] To run a local installation of webpack, you can access its binary at
node_modules/.bin/webpack. Alternatively, if you are using npm v5.2.0 or greater, you can runnpx webpack.
The following npm installation makes webpack available globally:
npm install --global webpack[!WARNING] This is not a recommended practice. Installing globally locks you into a specific version of webpack and may fail in projects that use a different version.
If you're eager to use the latest features webpack has to offer, you can install beta versions or even install directly from the webpack repository with the following commands:
npm install --save-dev webpack@next
# or a specific tag/branch
npm install --save-dev webpack/webpack#<tagname/branchname>[!WARNING] Take caution when installing these bleeding edge releases. They may still contain bugs and therefore should not be used in production.