--save와 --save-dev의 차이점은 무엇입니까?
차이점은 무엇입니까?
npm install [패키지 _ 이름] --save
과
npm 설치 [패키지 _ 이름] --save-dev
이것은 무엇을 의미 하는가?
--save-dev개발 목적으로 패키지를 저장하는 데 사용됩니다. 예 : 단위 테스트, 축소 ..--save애플리케이션 실행에 필요한 패키지를 저장하는 데 사용됩니다.
자신의 프로젝트에서 두 가지를 모두 시도했다면 --save과 의 차이 --save-dev가 즉시 눈에 띄지 않을 수 있습니다. 여기 몇 가지 예가 있습니다 ...
날짜를 구문 분석하고 표시하기 위해 moment 패키지를 사용하는 앱을 빌드한다고 가정 해 보겠습니다 . 앱은 스케줄러이므로 실행하려면이 패키지가 필요 합니다 . in : cannot run without it . 이 경우에는
npm install moment --save
그러면 package.json에 새 값이 생성됩니다.
"dependencies": {
...
"moment": "^2.17.1"
}
개발할 때 테스트 스위트와 같은 도구를 사용하는 것이 정말 도움이되며 jasmine-core 및 karma 가 필요할 수 있습니다 . 이 경우에는
npm install jasmine-core --save-dev
npm install karma --save-dev
이것은 또한 package.json에 새로운 값을 생성합니다.
"devDependencies": {
...
"jasmine-core": "^2.5.2",
"karma": "^1.4.1",
}
정상 상태에서 앱을 실행하는 데 테스트 스위트가 필요 하지 않으므로--save-dev 유형 종속성이며 그 이상은 아닙니다. 실제로 무슨 일이 일어나고 있는지 이해하지 못하면 상상하기가 조금 어렵다는 것을 알 수 있습니다.
NPM 문서 docs # dependencies 에서 직접 가져옴
의존성
종속성은 패키지 이름을 버전 범위에 매핑하는 단순 개체에 지정됩니다. 버전 범위는 공백으로 구분 된 설명자가 하나 이상있는 문자열입니다. 종속성은 tarball 또는 git URL로 식별 할 수도 있습니다.
종속성 개체에 테스트 도구 나 트랜스 파일러를 넣지 마십시오. 아래의 devDependencies를 참조하십시오 .
문서에서도 테스트 하네스와 같은 모듈에 --save-dev를 사용하도록 요청합니다.
이것이 도움이되고 명확하기를 바랍니다.
기본적으로 NPM은 단순히 node_modules 아래에 패키지를 설치합니다. 앱 / 모듈에 대한 종속성을 설치하려고 할 때, 당신은 먼저 설치 한 다음에 추가해야합니다 dependencies귀하의 섹션 package.json.
--save-dev타사 패키지를 패키지의 개발 종속성에 추가합니다. 누군가가 패키지를 설치할 때 설치되지 않습니다. 일반적으로 누군가 소스 저장소를 복제 하여 실행하는 경우에만 설치됩니다 npm install.
--save패키지의 종속성에 타사 패키지를 추가합니다. 누군가 실행될 때마다 패키지와 함께 설치됩니다 npm install package.
개발 종속성은 패키지 개발에만 필요한 종속성입니다. 여기에는 테스트 실행기, 컴파일러, 패키저 등이 포함될 수 있습니다. 두 유형의 종속성 모두 패키지 package.json파일에 저장 됩니다. --save에 추가 dependencies, --save-dev추가devDependencies
npm 설치 문서는 여기에서 참조 할 수 있습니다.
이에 대한 완벽한 예는 다음과 같습니다.
$ npm install typescript --save-dev
In this case, you'd want to have Typescript (a javascript-parseable coding language) available for development, but once the app is deployed, it is no longer necessary, as all of the code has been transpiled to javascript. As such, it would make no sense to include it in the published app. Indeed, it would only take up space and increase download times.
As suggested by @andreas-hultgren in this answer and according to the npm docs:
If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.
However, for webapp development, Yeoman (a scaffolding tool that installs a peer-reviewed, pre-written package.json file amongst other things) places all packages in devDependencies and nothing in dependencies, so it appears that the use of --save-dev is a safe bet in webapp development, at least.
--save-dev saves semver spec into "devDependencies" array in your package descriptor file, --save saves it into "dependencies" instead.
Clear answers are already provided. But it's worth mentioning how devDependencies affects installing packages:
By default, npm install will install all modules listed as dependencies in package.json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .
See: https://docs.npmjs.com/cli/install
You generally don't want to bloat production package with things that you only intend to use for Development purposes.
Use --save-dev (or -D) option to separate packages such as Unit Test frameworks (jest, jasmine, mocha, chai, etc.)
Any other packages that your app needs for Production, should be installed using --save (or -S).
npm install --save lodash //prod dependency
npm install -S moment // " "
npm install -S opentracing // " "
npm install -D jest //dev only dependency
npm install --save-dev typescript //dev only dependency
If you open the package.json file then you will see these entries listed under two different sections:
"dependencies": {
"lodash": "4.x",
"moment": "2.x",
"opentracing": "^0.14.1"
},
"devDependencies": {
"jest": "22.x",
"typescript": "^2.8.3"
},
Let me give you an example,
- You are a developer of a very SERIOUS npm library. Which uses different testing libraries to test the package.
- An user Downloaded your library and want to use it in their code. Do they need to download your testing libraries as well? Maybe you use
jestfor testing and they usemocha. Do you want them to installjestas well? To just run your lirary?
No. right? That's why they are in devDependencies.
When someone does, npm i yourPackage only the libraries required to RUN your library will be installed.
So, Why do the developers need to expose the devDependancies?
Let's say your package is an open source package and 100s of people are sending pull requests to your package. Then how they will test the package? They will git clone your repo and when they would do an npm i the dependencies as well as devDependencies. Because they are not using your package. They are developing the package further, thus the devDependencies are needed.
--save-dev is used for modules used in development of the application,not require while running it in production envionment --save is used to add it in package.json and it is required for running of the application.
Example: express,body-parser,lodash,helmet,mysql all these are used while running the application use --save to put in dependencies while mocha,istanbul,chai,sonarqube-scanner all are used during development ,so put those in dev-dependencies .
npm link or npm install will also install the dev-dependency modules along with dependency modules in your project folder
I want to add some my ideas as
I think all differents will appear when someone use your codes instead of using by yourself
For example, you write a HTTP library called node's request
In your library,
you used lodash to handle string and object, without lodash, your codes cannot run
If someone use your HTTP library as a part of his codes. Your codes will be compiled with his.
your codes need lodash, So you need put in dependencies to compile
If you write a project like monaco-editor, which is a web editor,
you have bundle all your codes and your product env library using webpack, when build completed, only have a monaco-min.js
So someone don't case whether --save or --save-dependencies, only he need is monaco-min.js
Summary:
If someone want to compile your codes (use as library), put
lodashwhich used by your codes intodependenciesIf someone want add more feature to your codes, he need
unit testandcompiler, put these intodev-dependencies
People use npm on production to do wicked cool stuff, Node.js is an example of this, so you don't want all your dev tools being run.
If you are using gulp (or similar) to create build files to put on your server then it doesn't really matter.
참고URL : https://stackoverflow.com/questions/22891211/what-is-the-difference-between-save-and-save-dev
'Programing' 카테고리의 다른 글
| 프로젝트에서 Git 추적을 제거하려면 어떻게합니까? (0) | 2020.10.03 |
|---|---|
| mysql_real_escape_string () 주위를 돌아 다니는 SQL 주입 (0) | 2020.10.03 |
| 중첩 된 JavaScript 개체 키의 존재 여부 테스트 (0) | 2020.10.03 |
| 텍스트 JavaScript에서 HTML 제거 (0) | 2020.10.03 |
| 뮤텍스 란 무엇입니까? (0) | 2020.10.03 |