source

@types/*가 'dependencies' 또는 'devendencies' 중 어느 쪽으로 갈지 어떻게 판단합니까?

goodcode 2023. 3. 27. 23:06
반응형

@types/*가 'dependencies' 또는 'devendencies' 중 어느 쪽으로 갈지 어떻게 판단합니까?

TypeScript 2 。라이브러리를 도 하고 .js 라 、 s 、 s 、 이 、 이 、 이 、 i i i i i i i i i i i i i i 。 단단 with with with ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★」npm install @types/some-library가 해야 --save ★★★★★★★★★★★★★★★★★」--save-dev 을 모두 .입력된 GitHub readme는 두 버전을 모두 언급하고 있지만 설명하지는 않습니다.@@types가 합니다.devDependencies@에 @는 단지 @types로 번 볼 수 dependencies저는 혼란스러워요.

@가 @types/* 에 여부를 ?dependencies ★★★★★★★★★★★★★★★★★」devDependencies인 지시가 더 실제로 공식적인 지침이 더 많거나 덜 있나요?

를 들어, 'A'가 있는 .@types/some-module포 in로 devDependencies로 에서 있습니다.@types/some-module:

import { SomeType } from 'some-module';

export default class APackageClass {
  constructor(private config: SomeType) {
    // …       
  }
}

는 현재 TypeScript가 무엇을 할 수 .SomeType, ★★★★★★★★★★★★★★★★~devDependencies패키지 "A"가 설치되지 않았습니다.

그런 경우에는 다음 위치를 지정하셔야 합니다.@types/*의 「」를 한 패키지dependencies 케이스는 ★★★★★★★★★★★★★★★★★★★★★devDependencies분합니니다다

하고 있는 번들을 구분하지 될.dependencies ★★★★★★★★★★★★★★★★★」devDependencies의 이 npm는 일반적으로 다른 사용자가 사용할 수 있는 패키지를 게시할 때 유용하며 중복 종속성으로 스팸을 발송하지 않습니다.

종속성을 분할하는 것이 도움이 될 수 있는 다른 사용 사례가 있을 수 있지만, 특별히 필요한 경우가 아니라면 하나만 선택하고 모든 항목을 여기에 배치하는 것이 좋습니다.필요에 따라 분할하는 것은 어렵지 않습니다.

의 잘 로는 IRL이 있습니다.create-react-app을 "Displate"에 배치합니다.dependencies, 이 스레드와 이 답변참조해 주세요.

Node.js 어플리케이션을 실가동 환경에 도입하는 경우 어플리케이션 실행에 필요한 의존관계만 설치해야 합니다.

npm install --production or or or openicle.

npm ci --production or or or openicle.

yarn --production

경우, 그 은 '아까보다'에.devDependencies설치를 부풀리지 않도록 합니다.

)--production어플리케이션이 빌드된 머신에서는 옵션을 사용하지 마십시오.TypeScript )))))))))))))))))))))))))) 。

Remarks: I'm aware this was mentioned in a comment by Brad Wilson to another answer. This point seems worthy to be an answer, though.

다른 답변도 일리가 있지만 peerDep 유형 선언 패키지도 다음 중 하나에 배치해야 합니다.dependencies대신peerDependencies.

라고 가정합니다.b의 플러그인입니다.a.그리고.c사용하다a그리고.b.

왜 안 돼?@types/a에 배치되다bpeerDependencies?

한다면bpackage.json다음과 같습니다.

{
  "peerDependencies": {
    "a": "1.5.x"
    "@types/a": "1.4.x"
  }
}

c에서 정의된 인터페이스만 사용할 수 있습니다.@types/a@1.2.x그렇지만c를 강제적으로 인스톨되다@types/a@1.4.x.

더 나아가,ctypescript 패키지가 아닌 일반 javascript 패키지일 수 있지만c설치도 강제됩니다.@types/a@1.4.x.

그래서 정답은package.jsonb다음과 같아야 합니다.

{
  "peerDependencies": {
    "a": "1.5.x"
  },
  "dependencies": {
    "@types/a": "1.4.x"
  }
}

ReferenceURL : https://stackoverflow.com/questions/45176661/how-do-i-decide-whether-types-goes-into-dependencies-or-devdependencies

반응형