预发布未按预期工作

Prepublish not working as expected

我正在测试 npm 脚本以构建我的项目依赖项。

我的想法来自 https://github.com/ParsePlatform/parse-server,它让我印象深刻的是存储库中的代码并不意味着 npm install 之后 node_modules 中的代码。

下面是我的测试模块结构

src/index.js
package.json

这是我的package.json内容

{
  "name": "testmodule",
  "version": "1.0.0",
  "description": "",
  "main": "lib/index.js",
  "scripts": {
    "build": "babel src/ -d lib/",
    "prepublish": "npm run build"
  },
  "devDependencies": {
    "babel-cli": "^6.18.0",
    "babel-core": "^6.18.2"
  }
}

这是我在 运行 npm install testmodule

之后期望的结构
node_modules/testmodule/lib/index.js
node_modules/testmodule/package.json

src 文件夹不应该在这里。

但是在我运行npm install之后,它和我推送到我的git仓库时完全一样。

请注意,我在自己的服务器中使用 GitLab

所以我的问题是:

  1. 我是否缺少任何预发布内容运行?

  2. parse-server 代码的哪一部分导致安装后src 文件夹和其他文件不存在?

你好吗运行宁npm install

根据 documentation on npm scripts,预发布脚本是 运行 "BEFORE the package is published. (Also run on local npm install without any arguments.)"。很明显,预发布脚本仅在 npm publishnpm install <local directory>.

上 运行

如果您尝试通过 URL 从本地 gitlab 服务器直接安装,这 不会 工作 - 脚本不会 运行 .解决方案是在本地安装,除非您愿意开源您的包并将其推送到 npm 存储库或支付私有 npm 存储库的费用。这是我在开发包之前所做的事情 public.