npm을 사용하여 rubygems 용 번 들러처럼 필수 패키지를 설치하거나 업데이트합니다.
나는 Bundler를 좋아하며 의존성 관리에 탁월합니다. 나는 npm을 좋아 합니다. 노드 패키지를 설치하는 것은 쉽습니다! 저는 nodejs 앱을 가지고 있고 앱 종속성을 지정하고 앱을 배포 할 때마다 쉽게 설치 / 업데이트 할 수 있기를 바랍니다 . 이것은 내가 공개하는 라이브러리가 아니라 본격적인 웹 앱입니다.
나는 npm bundle
명령을 알고 있지만 단순히 패키지가 설치된 디렉토리를 무시하는 것 같습니다.
나는 이러한 방식으로 번 들러를 사용하는 데 익숙합니다.
# Gemfile
gem "rails", "3.0.3"
Rails v3.0.3 및 기타 필수 gem이 아직없는 경우에만 호스트 머신에 설치합니다.
> bundle install
npm으로 비슷한 것을 어떻게 얻을 수 있습니까?
npm 1.0 (README 파일의 단계를 수행하면 기본적으로 제공됨)부터 "번들"은 더 이상 분리 된 것이 아니라 "작동 방식"입니다.
그래서:
package.json
프로젝트의 루트에 파일을 넣으십시오.해당 파일에 귀하의 부서를 나열하십시오
{ "name" : "my-project" , "version" : "1.0.0" , "dependencies" : { "express" : "1.0.0" } }
npm install
전역 모드가 아닌 인수없이 이것을 호출하므로 모든 deps를 로컬에 설치합니다.require("express")
행복하세요.
편집 : 이것은 npm 버전 <1.0에만 적용됩니다.
이것을 알아내는 것은 매우 어려웠지만 NPM은 이것을 가능하게합니다 .
세 가지 구성 요소가 필요합니다
- 저장소에있는 하위 디렉토리 (예
deps/
) package.json
종속성을 나열하는 위 디렉토리 의 파일index.js
종속성이 필요한 위 디렉토리 의 파일
예
표현 이 유일한 의존 이라고 상상해보세요
deps / package.json
참고 : 종속성을 수정할 때마다 버전 번호를 늘립니다.
{
"name": "myapp_dependencies",
"version": "0.0.1",
"engines": {
"node": "0.4.1"
},
"dependencies":{
"express": "2.0.0beta2"
}
}
deps / index.js
export.modules = {
express: require('express')
//add more
}
이제 npm을 사용하여 종속성을 설치할 수 있습니다. 이 부분을 배포 프로세스의 일부로 만들 수도 있습니다.
cd deps
npm install
그런 다음 앱 코드 내에서 다음과 같이 특정 버전의 Express에 액세스 할 수 있습니다.
var express = require('myapp_dependencies').express;
Isaacs (author npm) 블로그에서이 두 기사를 읽어야합니다. 나는 그들이 정말 훌륭하다고 생각하며 목표를 달성하는 방법을 알려줍니다.
- http://blog.izs.me/post/1675072029/10-cool-things-you-probably-didnt-realize-npm-could-do
- http://foohack.com/2010/08/intro-to-npm/
나는 링크 # 1 (포인트 # 11)이 이것을 설명한다고 믿는다.
11 : 모든 종속성을 패키지 자체에 번들링
When you use the npm bundle command, npm will put all your dependencies into the node_modules folder in your package. But it doesn’t stop there.
If you want to depend on something that’s not on the registry, you can do that. Just do this:
npm bundle install http://github.com/whoever/whatever/tarball/master This will install the contents of that tarball into the bundle, and then you can list it as a dependency, and it won’t try to install it when your package gets installed.
This also is handy if you have your own fork of something, and would prefer not to change the name.
In fact, you can run almost any npm command at the bundle. To see what’s inside, you can do npm bundle ls. To remove something, do npm bundle rm thing. And, of course, you can install multiple versions and activate the one you want.
As of Npm version 1.1.2 , there's a new command npm shrinkwrap
which creates an npm-shrinkwrapped.json
file, analogous to Gemfile.lock
. It's important to make one, to prevent software rot (see Bundler's rationale). Particularly as Nodejs has such a fast moving community.
While bundle install
creates a Gemfile.lock
automatically, npm install
won't create npm-shrinkwrapped.json
(but will use it when it exists). Hence you need to remember to use npm shrinkwrap
.
Read a full guide at http://blog.nodejs.org/2012/02/27/managing-node-js-dependencies-with-shrinkwrap/
It seems to me that the simplest solution is to use a package.json
file with the private
flag (added to npm just last month) set to true
. That way, you can run npm install
or npm bundle
to grab your project's dependencies, but you prevent anyone from accidentally publishing your non-public project.
Here's an example package.json
:
{
"name": "yourProject"
,"version": "1.0.0"
,"dependencies": { "express" : ">=2.1.0" }
,"private": true
}
Running npm install
will install express
on the local system if it doesn't already exist; running npm publish
gives an error because of the "private": true
.
You and your team can use the version tag internally to track dependency changes over time—each time you change a dependency, bump the version. To see which version you've installed, use npm ls installed
.
Publish your app with npm
as well, and list its dependencies in your package.json file.
When someone uses npm
to install your package, npm
will take care of resolving its dependencies.
Packages spec: http://wiki.commonjs.org/wiki/Packages/1.0
'programing tip' 카테고리의 다른 글
1-10 범위의 난수 생성 (0) | 2020.09.14 |
---|---|
svn diff를 만드는 방법 두 개정 사이에 공백이 아닌 줄 변경 만 표시 (0) | 2020.09.14 |
matplotlib의 그림 내에서 각 플롯 된 선에 대해 새 색상을 선택하는 방법은 무엇입니까? (0) | 2020.09.14 |
균형 잡힌 나무의 정의 (0) | 2020.09.14 |
nodejs에서 스레드를 만드는 방법 (0) | 2020.09.14 |