【问题标题】:package.json: Just download dependency but do not install itpackage.json: 只下载依赖但不安装
【发布时间】:2017-06-27 15:57:33
【问题描述】:

我即将编写一个 yeoman 生成器,其中整个模板都托管在 git 存储库中。所以我的 yeoman 生成器的 package.json 看起来像

{
  "name": "generator-foo",
  "version": "0.1.0",
  "description": "",
  "files": [
    "generators"
  ],
  "keywords": [
    "yeoman-generator"
  ],
  "dependencies": {
    "foo-template": "git://somewhere-in-the-world/foo-template.git#0.1.0",
    "chalk": "^1.1.3",
    "yeoman-generator": "^1.1.1",
    "yosay": "^2.0.0"
  }
}

有没有办法阻止npm install 安装foo-template 包,即只为这个包运行任何安装后脚本?相反,它应该只是下载到node_modules

【问题讨论】:

  • 安装是什么意思?喜欢调用安装后挂钩?
  • 不,这不是这些问题的重复。在这两个问题中,都要求禁用所有安装后脚本。我想要的是防止在 foo-template 中运行 postinstall 脚本,但在所有其他包中。
  • 好的,谢谢更详细的解释!
  • 我很好奇:您为什么要跳过特定软件包的安装后脚本?

标签: npm yeoman npm-install


【解决方案1】:

As describe here,可以使用--ignore-scripts 标志为 npm 全局禁用安装后脚本。

作为一个完整的解决方案,我会将您对 foo-template 的显式依赖项移至启用忽略脚本的本地安装后部分:

{
  "name": "generator-foo",
  ...
  "postinstall": "npm install --ignore-scripts git://somewhere-in-the-world/foo-template.git#0.1.0",
  "peerDependencies": {
    "foo-template": "git://somewhere-in-the-world/foo-template.git#0.1.0" 
  }
}

请注意,为了确保明确描述依赖关系,我们应该将其标记为 peerDependency(例如,防止在 prune 上删除包)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-24
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2016-09-09
    相关资源
    最近更新 更多