企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**Install** [[[webpack官方网站-installed](https://webpack.js.org/guides/installation)] [TOC] ## Local Installation Before we begin, make sure you have a fresh version of [Node.js](https://nodejs.org/en/) installed. The current Long Term Support (LTS) release is an ideal starting point. To install the latest release or a specific version, run one of the following commands: ~~~bash npm install --save-dev webpack npm install --save-dev webpack@<version> ~~~ If you're using webpack v4 or later, you'll also need to install the[CLI](https://webpack.js.org/api/cli/). ~~~bash npm install --save-dev webpack-cli ~~~ Installing locally is what we recommend for most projects. This makes it easier to upgrade projects individually when breaking changes are introduced. Typically webpack is run via one or more [npm scripts](https://docs.npmjs.com/misc/scripts) which will look for a webpack installation in your local `node_modules` directory: ~~~json "scripts": { "build": "webpack --config webpack.config.js" } ~~~ >[info] To run the local installation of webpack you can access its binary version as `node_modules/.bin/webpack`. > Alternatively, if you are using npm v5.2.0 or greater, you can run 'npx webpack' to do it. First let's create a directory `webpack-demo`, initialize npm, install webpack locally, and install the webpack-cli (the tool used to run webpack on the command line): ~~~bash mkdir webpack-demo cd webpack-demo npm init -y npm install webpack --save-dev npm install webpack-cli --save-dev ~~~ >[info] When installing a package that will be bundled into your production bundle, you should use `npm install --save`, `package.json->"dependencies"`. > If you're installing a package for development purposes (e.g. a linter, testing libraries, etc.) then you should use `npm install --save-dev`, `package.json->"devDependencies"` ## Global Installation The following NPM installation will make `webpack` available globally: ~~~bash npm install --global webpack ~~~ >[warning] Note that this is **not a recommended practice**. Installing globally locks you down to a specific version of webpack and could fail in projects that use a different version.