虽然这可能不是 nodejs 的方式,一些纯粹主义者可能会抱怨,Composer 会做你想做的事。即使 Composer 用于 PHP 项目,也没有理由不能使用它来管理 nodejs 项目的 3rd 方 non-npm 存储库。显然,第 3 方库最好包含一个 package.json,但这不会发生。我在我当前的 nodejs 应用程序上尝试了这个,它对我来说非常有效。
优点:
- 一个 json 文件指定没有 package.json 文件的自定义外部依赖项
- 自定义包在项目文件夹中的存储位置
- 适用于私有存储库和最初不用于 nodejs 的存储库
缺点:
- 需要 php cli
- 更新依赖项的额外步骤
- 依赖项的额外 json 文件
这里怎么做(你需要能够从cli运行php):
1.下载 Composer(直接进入你的 nodejs 项目根目录)
curl -s https://getcomposer.org/composer.phar > composer.phar
2。创建 composer.json 文件(在项目的根目录中)
{
"repositories": [
{
"type": "package",
"package": {
"name": "twitter/bootstrap",
"version": "2.0.0",
"dist": {
"url": "https://github.com/twitter/bootstrap/zipball/master",
"type": "zip"
},
"source": {
"url": "https://github.com/twitter/bootstrap.git",
"type": "git",
"reference": "master"
}
}
}
],
"require": {
"twitter/bootstrap": "2.0.0"
}
}
3。运行 Composer 更新
php composer.phar update
这将按照您的要求将包下载到vendor 文件夹中:
├── vendor
│ ├── ...
│ ├── composer
│ │ └── installed.json
│ └── twitter
│ └── bootstrap
│ ├── LICENSE
│ ├── Makefile
│ ├── README.md
│ ├── docs
│ │ ├── assets
│ │ └── ...
│ ├── img
│ │ ├── glyphicons-halflings-white.png
│ │ └── glyphicons-halflings.png
│ ├── js
│ │ ├── bootstrap-affix.js
│ │ └── ...
│ ├── less
│ │ ├── accordion.less
│ │ └── ...
│ └── ...