npm install 不是从依赖项安装 grunt js

kob*_*obe 2 node.js gruntjs

我正在尝试为开发人员自动安装所有软件包。所以我在同一个目录中有 package.json 和 grunt 文件。我想先执行 npm install 以便安装所有依赖项,当开发人员在命令行上执行 grunt 时,一切就准备好了。我可以知道为什么它不起作用。另一件事是我可能知道依赖和开发依赖之间的区别。

{
  "name": "TestProject",
  "version": "0.1.0",
  "description": "this project is for test",
  "main": "index.js",
  "dependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-uglify": "~0.2.7",
    "uglify-js": "~2.4.3",
    "grunt-contrib-watch":"~0.5.3",
    "grunt-contrib-jshint": "~0.7.2",
    "qunit": "~1.11.0"
  },  
  "devDependencies": {
    "grunt": "~0.4.2",
    "qunit": "~1.11.0",
    "grunt-contrib-jshint": "~0.7.2",
    "grunt-contrib-nodeunit": "~0.2.0",
    "grunt-contrib-uglify": "~0.2.2",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-contrib-watch":"~0.5.3"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "BSD-2-Clause"
}
Run Code Online (Sandbox Code Playgroud)

bev*_*qua 5

您可能缺少 Grunt 的命令行实用程序。

它可以安装在你的 shell 中,使用

npm install -g grunt-cli
Run Code Online (Sandbox Code Playgroud)

CLI 独立于grunt包或grunt-插件分发。您应该grunt-cli在同一个开发环境设置文档中包含全局安装说明,在该文档中指明如何设置nodenpmbower等。

更新

如果你是如此的坚定的关于安装grunt-clinpm install,我想一个选项可能会使用NPM脚本

包括在您的package.json (注:未经测试)

{
  "postinstall": "npm i -g grunt-cli"
}
Run Code Online (Sandbox Code Playgroud)

不过,我不鼓励这样做。只需手动安装它们。

  • `package.json` 中的依赖项是特定于包的。`grunt-cli` 之类的工具不应该包含在 `package.json` 中,就像 `npm`、`node`、`bower` 或 `component` 不应该包含在内。它们是 CLI 工具,而不是运行时(甚至是开发)依赖项。您的项目不直接依赖于 CLI。你这样做,在全球范围内。 (2认同)