【问题标题】:How to make a forked dependency in package.json run its prepare script during npm install?如何使 package.json 中的分叉依赖项在 npm 安装期间运行其准备脚本?
【发布时间】:2017-08-26 06:09:01
【问题描述】:

我 fork a NPM module 并在 my fork 中修改它。在我的 fork 中,需要运行命令 gulp 来编译模块。运行此命令会将文件ical-expander-dist.js 输出到dist 文件夹中。这个文件应该成为 fork 包的一部分。

在我的 fork 中调整后的 package.json 如下所示:

{
  "name": "ical-expander",
  "version": "1.1.1",
  "description": "ICS / iCal / iCalendar parser / expander",
  "main": "dist/ical-expander-dist.js", // adjusted path
  "scripts": {
    "prepare": "gulp" // added script
  },
  // [SNIP] - excluded irrelevant lines
  "files": [
    "dist/ical-expander-dist.js" // adjusted path
  ]
}

现在我想让我的 fork 成为另一个项目的依赖项。

{
  "name": "otherproject",
  "title": "Other Project",
  // [SNIP] - excluded irrelevant lines
  "dependencies": {
    "ical-expander": "github:haukepribnow/ical-expander"
  }
  // [SNIP] - excluded irrelevant lines
}

在otherproject的根文件夹中执行npm install后,路径./node_modules/ical-expander将包含文件LICENSE、README.md和package.json。但是它不会包含dist/ical-expander-dist.js。

看起来我的 ical-expander fork 的 prepare 脚本没有在 npm install in otherproject 中运行。


所以我的问题归结为:在将我的 fork 作为其依赖项之一的项目中执行 npm install 时,如何确保正在运行用于编译我的 fork 的准备脚本?

【问题讨论】:

    标签: npm dependencies


    【解决方案1】:

    有时很简单:确保使用npm 5.0.0 或更高版本。

    根据the npm changelog,npm install 将从 5.0.0 开始正确运行依赖项的 prepare 脚本。

    【讨论】:

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