본문으로 건너뛰기
버전: Next

동기

Saving disk space

An illustration of the pnpm content-addressable store. On the illustration there are two projects with node_modules. The files in the node_modules directories are hard links to the same files in the content-addressable store.

npm을 사용할 때 종속성을 사용하는 프로젝트가 100개 있는 경우 해당 종속성의 사본 100개가 디스크에 저장됩니다. pnpm을 사용하면 의존성이 content-addressable 저장소에 저장되므로, 다음을 따릅니다.

  1. 다른 버전의 의존성에 여러분이 의존하는 경우, 다른 파일만이 저장소에 추가됩니다. 예를 들어, 100개의 파일이 있고 새 버전이 해당 파일 중 하나만 변경되면, pnpm update 는 단일 항목의 변경에 대해 전체 파일이 복제되는 대신, 저장소에 1개의 새로운 파일만 추가합니다.
  2. 모든 파일은 디스크 상에서 단일 위치에 저장됩니다. 패키지가 설치될 때 그 파일들은 단일 위치에서 하드링크되며 추가적인 디스크 공간을 소비하지 않습니다. 이를 통해 프로젝트 간에 동일한 버전의 의존성을 공유할 수 있습니다.

결과적으로, 여러분의 디스크 공간은 프로젝트와 의존성의 수에 비례하여 더 많이 절약되고 더 빠르게 설치할 수 있습니다!

Boosting installation speed

pnpm performs installation in three stages:

  1. Dependency resolution. All required dependencies are identified and fetched to the store.
  2. Directory structure calculation. The node_modules directory structure is calculated based on the dependencies.
  3. Linking dependencies. All remaining dependencies are fetched and hard linked from the store to node_modules.

An illustration of the pnpm install process. Packages are resolved, fetched, and hard linked as soon as possible.

This approach is significantly faster than the traditional three-stage installation process of resolving, fetching, and writing all dependencies to node_modules.

An illustration of how package managers like Yarn Classic or npm install dependencies.

평탄하지 않은 node_modules 디렉토리 생성

npm 또는 Yarn 클래식을 통해 의존성을 설치할 때, 모든 패키지는 모듈 디렉토리의 루트로 호이스트됩니다. 결과적으로, 소스 코드는 프로젝트에 의존성으로 추가되지 않은 의존성에 접근할 수 있습니다.

기본적으로, pnpm은 symlink를 사용하여 프로젝트의 직접적인 의존성만을 모듈 디렉토리의 루트로 추가합니다.

An illustration of a node_modules directory created by pnpm. Packages in the root node_modules are symlinks to directories inside the node_modules/.pnpm directory

pnpm이 생성하는 고유한 node_modules 구조의 자세한 사항 및 이것이 Node.js 생태계에서 잘 작동하는 이유에 대해 자세히 아고 싶다면, 다음을 읽어보세요.

tip

If your tooling doesn't work well with symlinks, you may still use pnpm and set the nodeLinker setting to hoisted. 이것은 pnpm이 npm 및 Yarn 클래식에서 생성한 것과 유사하게 node_modules 디렉토리를 생성하도록 지시합니다.