使用npm来安装或更新必需的包,就像用于rubygem的bundler一样 [英] Using npm to install or update required packages just like bundler for rubygems
问题描述
我喜欢 Bundler ,它非常适合依赖关系管理。我喜欢 npm ,安装节点包很容易!我有一个nodejs应用程序,并希望能够指定我的应用程序依赖关系,并轻松地安装/更新他们,无论我在哪里部署我的应用程序。这不是我发布的图书馆,它是一个完整的网络应用程序。
I love Bundler, it's great at dependency management. I love npm, installing node packages is easy! I have a nodejs app and would love to be able to specify my apps dependencies and easily install / update them wherever I deploy my app. This isn't a library I'm releasing, it's a full fledged web-app.
我知道 npm bundle
命令,但这似乎只是覆盖安装软件包的目录。
I'm aware of the npm bundle
command, but that just seems to simply override the directory where packages are installed.
我习惯于以这种方式使用bundler:
I'm used to using bundler in this fashion:
# Gemfile
gem "rails", "3.0.3"
只有在主机上尚不存在,才能在主机上安装rails v3.0.3和任何其他所需的gem。
Installs rails v3.0.3 and any other required gems on the host machine only if it doesn't already exist
> bundle install
如何实现与npm类似的东西?
推荐答案
从npm 1.0开始(现在,如果您按照README文件中的步骤,默认情况下可以获得),bundle不再是隔离的东西 - 这只是如何运作。
As of npm 1.0 (which is now what you get by default if you follow the steps in the README file), "bundle" is no longer a segregated thing -- it's just "how it works".
所以:
- 将
package.json
文件放在项目的根目录中 -
在该文件中列出您的deps
- Put a
package.json
file in the root of your project List your deps in that file
{ "name" : "my-project"
, "version" : "1.0.0"
, "dependencies" : { "express" : "1.0.0" } }
npm install
由于您没有参与调用,而不是全局模式,所以只需在本地安装所有的deps。
npm install
Since you're calling this with no args, and not in global mode, it'll just install all your deps locally.
这篇关于使用npm来安装或更新必需的包,就像用于rubygem的bundler一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!