node.js Gulp 构建不会自动安装依赖项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29325983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:34:59  来源:igfitidea点击:

Gulp build does not install dependencies automatically?

node.jsbuilddependenciesnpmgulp

提问by Gelin Luo

I use gulp to build my javascript application. I have some dependencies declared in the package.jsonfile, for example:

我使用 gulp 来构建我的 javascript 应用程序。我在package.json文件中声明了一些依赖项,例如:

"dependencies": {
  "flux": "^2.0.1",
  "keymirror": "~0.1.0",
  "object-assign": "^1.0.0",
  "react": "^0.13.1",
  "dropzone": "^4.0.1",
  "lodash": "^3.6.0"
}

When I run gulp build, it always prompt me some dependency cannot be found unless I manually run npm install lodashfor example.

当我运行 gulp build 时,它总是提示我找不到某些依赖项,除非我手动运行npm install lodash

Is there a way to have gulp run npm installautomatically?

有没有办法让 gulpnpm install自动运行?

回答by Alex

Run npm install --save-devcommand to resolve all dependencies.

运行npm install --save-dev命令以解决所有依赖项。

Here is link to documentation with --save-devparameter description: https://docs.npmjs.com/cli/install

这是带有--save-dev参数描述的文档链接:https: //docs.npmjs.com/cli/install

回答by Vikas Kathunia

  1. You require to have package.json on the root level.
  2. Then once you have to run npm install for all the dependencies with --saveDev(development dependencies) or --save(project level dependencies).
  3. Once this is done, for the next time only run npm install command will install dependent dependencies.
  1. 您需要在根级别拥有 package.json。
  2. 然后,一旦您必须使用 --saveDev(开发依赖项)或 --save(项目级依赖项)为所有依赖项运行 npm install。
  3. 完成后,下次只运行 npm install 命令将安装依赖项。

回答by halogenr

gulp-installwould help for your issue. Go to NPM(node package manager) and search for "gulp-install".

gulp-install将帮助您解决问题。转到NPM(节点包管理器)并搜索“gulp-install”。

The node plugin gulp-installautomatically installs packages/dependencies for npm, bower, tsd, and pip. The relative configurations must be found in the gulp file stream.

node 插件会gulp-install自动为 npm、bower、tsd 和 pip 安装包/依赖项。必须在 gulp 文件流中找到相关配置。

Example Usage:

示例用法

In your gulpfile.js:

在你的 gulpfile.js 中:

var install = require("gulp-install");

gulp.src(["./package.json", "./bower.json"])
  .pipe(install());