pnpm deploy

워크스페이스에서 패키지를 배포합니다. 배포 중에 배포된 패키지의 파일이 대상 디렉터리에 복사됩니다. 워크스페이스의 종속성을 포함하여 배포된 패키지의 모든 종속성은 대상 디렉터리의 독립된 node_modules 디렉터리 내에 설치됩니다. 대상 디렉터리에는 추가 단계 없이 서버에 복사하고 실행할 수 있는 이식 가능한 패키지가 포함됩니다.

When the selected project declares a link: dependency on a directory outside the workspace projects, pnpm resolves its dependencies and includes the package in the deployment.

참고

Since v12.2.0, pnpm deploy no longer requires injectWorkspacePackages. A linked workspace dependency is rewritten to a file: dependency in the dedicated deploy lockfile. The peer dependencies it declares are bound the way an injected install binds them: to the version its parent provides. If the parent does not depend on the peer, pnpm looks further up, to the deployed project. A peer that no ancestor provides is bound to the deployed graph's own resolution. This includes optional peers declared only in peerDependenciesMeta.

The binding is ambiguous when the ancestors provide more than one package or version, or when no ancestor provides the peer and the deployed graph holds more than one version. The deploy then fails with ERR_PNPM_DEPLOY_AMBIGUOUS_PEER, naming the package, the peer, and the competing resolutions. Pin the peer to one version with an overrides entry, or turn injectWorkspacePackages on, which is the setting that decides between the candidates.

Before v12.2.0, the command refused every non-injected workspace up front. --legacy, or forceLegacyDeploy: true, still selects the older implementation.

참고

enableGlobalVirtualStore 옵션이 설정되어 있어도 pnpm deploy는 이를 무시하고 항상 배포 디렉터리 내에 로컬 가상 스토어를 생성합니다. 이렇게 하면 배포 디렉터리가 자체적으로 완결되고 이식 가능한 상태로 유지됩니다.

사용법:

pnpm --filter=<deployed project name> deploy <target directory>

The filter must select exactly one project. Selecting none fails with ERR_PNPM_NOTHING_TO_DEPLOY, and selecting several fails with ERR_PNPM_CANNOT_DEPLOY_MANY. A target directory that is unsafe to write, such as the workspace root, fails with ERR_PNPM_INVALID_DEPLOY_TARGET.

Relative file: paths in root overrides are resolved from the source workspace. Their dependencies are included in the deployed package.

배포 전에 프로젝트를 빌드하는 경우, --prod 옵션을 사용하여 devDependencies 설치를 건너뜁니다.

pnpm --filter=<deployed project name> --prod deploy <target directory>

도커 이미지에서의 사용. 모노레포에서 모든 것을 빌드한 후 모노레포 기본 이미지를 빌드 컨텍스트로 사용하는 두 번째 이미지 또는 추가 빌드 단계에서 이 작업을 수행하세요.

Dockerfile
# syntax=docker/dockerfile:1.4

# The workspace image must use WORKDIR /app
FROM workspace as pruned
RUN pnpm --filter <your package name> --prod deploy pruned

FROM node:22-alpine
WORKDIR /app

ENV NODE_ENV=production

COPY --from=pruned /app/pruned .

ENTRYPOINT ["node", "index.js"]

A deployed symlink to a directory inside the project is kept even if the directory is not deployed. So is a symlink to a missing path inside the project, such as a link into a removed node_modules. A link into node_modules resolves to the dependency installed in the output directory. A symlink to a file that is not deployed is replaced by a copy of the file.

To deploy without registry metadata, keep the source lockfile and populate the store with pnpm install or pnpm fetch before running pnpm deploy --offline. This also works with per-project lockfiles and --legacy. Use --trust-lockfile if deployment should skip supply-chain policy checks on the locked dependencies. New or changed dependencies may still require registry metadata.

Deployment preserves the recorded peer bindings of injected workspace packages, including when using lockfile.format: v13.

옵션#

pnpm deploy accepts the options of pnpm install for the install it runs into the target directory.

--force#

Allow deployment to a non-empty target directory. Without this flag, pnpm fails with ERR_PNPM_DEPLOY_DIR_NOT_EMPTY if the target directory is not empty.

--ignore-scripts#

Skip lifecycle scripts during deployment, including dependency build scripts. See pnpm install --ignore-scripts.

--dev, -D#

devDependencies만 설치됩니다.

--no-optional#

optionalDependencies는 설치되지 않습니다.

--prod, -P#

devDependencies의 패키지는 설치되지 않습니다.

--filter <package_selector>#

필터링에 대해 자세히 알아보세요.

--legacy#

레거시 배포 구현을 강제로 사용합니다.

기본적으로 pnpm deploy는 배포를 위해 공유 lockfile로부터 전용 lockfile을 생성하려고 시도합니다. The --legacy flag disables this behavior.

Since v12.4.1, the legacy implementation prefers the versions the source workspace lockfile pins, wherever they still satisfy the deployed project's ranges.

Since v12.16.0, it checks the source workspace lockfile against minimumReleaseAge and the other resolution policies first, as pnpm install does, and fails if one of them rejects a locked version. trustLockfile or --trust-lockfile skips that check.

What the deployed project gets#

  • The packageManager and devEngines.packageManager fields of the workspace root package.json are not copied into the deployed package.json.
  • The virtual store is placed at virtualStoreDir, resolved against the deploy directory. With the global virtual store enabled or an absolute virtualStoreDir, it stays at node_modules/.pnpm.
  • The prepare script of the deployed project is not run.
  • A workspace project that the deploy installs as a file: dependency runs its build scripts. pnpm approves it by its dependency path in the allowBuilds setting. An allowBuilds entry that denies the project still applies.
  • A workspace project with publishConfig.directory is installed from that directory. Its build scripts run only if the directory is inside the project and not inside node_modules.

Reproducible output#

Since v12.15.0, when the SOURCE_DATE_EPOCH environment variable is set, pnpm deploy and pnpm install use it as an upper bound for the timestamps in node_modules/.modules.yaml and node_modules/.pnpm-workspace-state-v1.json. With an equivalently prepared deploy target and an epoch no later than the timestamps that would otherwise be recorded, deploying the same project with the same lockfile produces identical files, so a Docker layer built from the deploy directory stays cached.

The next pnpm install or pnpm run in that directory checks the installed dependencies against the lockfile instead of trusting file modification times.

배포된 프로젝트에 포함된 파일#

By default, pnpm copies the files that pnpm pack would include. They are selected in one of the following ways, resolved in order:

  1. 프로젝트의 package.json에는 복사해야 하는 파일과 디렉터리가 나열된 files 필드가 포함될 수 있습니다.
  2. 애플리케이션 디렉터리에 .npmignore 파일이 있으면 여기에 나열된 모든 파일이 무시됩니다.
  3. 애플리케이션 디렉터리에 .gitignore 파일이 있으면 여기에 나열된 모든 파일이 무시됩니다.

To copy every file of the project, set deployAllFiles to true.

환경설정#

forceLegacyDeploy#

  • 기본값: false
  • 유형: Boolean

기본적으로 pnpm deploy는 배포를 위해 공유 lockfile로부터 전용 lockfile을 생성하려고 시도합니다. 이 설정을 true로 설정하면 레거시 deploy 동작이 사용됩니다.