pnpm deploy
Desplega un paquete desde un workspace. Durante el despliegue, los archivos del paquete desplegado se copian al directorio de destino. All dependencies of the deployed package, including dependencies from the workspace, are installed inside an isolated node_modules directory at the target directory. El directorio de destino contendrá un paquete portátil que puede ser copiado a un servidor y ejecutado sin pasos adicionales.
note
Since v11.26.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 v11.26.0 the command refused every non-injected workspace up front. --legacy, or forceLegacyDeploy: true, still selects the older implementation.
note
When the enableGlobalVirtualStore option is set, pnpm deploy ignores it and always creates a localized virtual store within the deploy directory. This keeps the deploy directory self-contained and portable.
Uso:
pnpm --filter=<deployed project name> deploy <target directory>
In case you build your project before deployment, also use the --prod option to skip devDependencies installation.
pnpm --filter=<deployed project name> --prod deploy <target directory>
Uso en una imagen docker. Después de generar todo en su monorepo, haga esto en una segunda imagen que use su imagen base monorepo como contexto de construcción o en una etapa de generación adicional:
# syntax=docker/dockerfile:1.4
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.
Opciones#
--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#
Only devDependencies are installed.
--no-optional#
optionalDependencies are not installed.
--prod, -P#
Packages in devDependencies won't be installed.
--filter <package_selector>#
--legacy#
Force legacy deploy implementation.
By default, pnpm deploy will try creating a dedicated lockfile from a shared lockfile for deployment. The --legacy flag disables this behavior and also allows using the deploy command without the inject-workspace-packages=true setting.
Archivos incluidos en el proyecto desplegado#
By default, pnpm copies the files that pnpm pack would include. They are selected in one of the following ways, resolved in order:
- The project's
package.jsonmay contain a "files" field to list the files and directories that should be copied. - If there is an
.npmignorefile in the application directory then any files listed here are ignored. - If there is a
.gitignorefile in the application directory then any files listed here are ignored.
To copy every file of the project, set deployAllFiles to true.
Since v11.28.0, symlinks that point to files or directories included in the deployed project are kept as symlinks.
The deployed project#
Since v11.28.0:
- The
packageManageranddevEngines.packageManagerfields of the workspace rootpackage.jsonare not copied into the deployedpackage.json. Versions v11.28.0 through v11.28.x copied them. - The virtual store is created at
virtualStoreDir, resolved against the deploy directory. A deploy from a shared lockfile recordsvirtualStoreDirin the deployedpnpm-workspace.yaml. With the global virtual store enabled or an absolutevirtualStoreDir, the deploy usesnode_modules/.pnpm. - The
preparescript of the deployed project is not run. --package-import-methodpassed on the command line is respected.
Since v11.28.12, 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 project with publishConfig.directory is installed from that directory, and its build scripts run only if the directory is inside the project and not inside node_modules.
Configuración#
forceLegacyDeploy#
- Default: false
- Type: Boolean
By default, pnpm deploy will try creating a dedicated lockfile from a shared lockfile for deployment. If this setting is set to true, the legacy deploy behavior will be used.