pnpm deploy
从工作区部署一个包。在部署过程中,已部署包的文件会被复制到目标目录。已部署包的所有依赖,包括工作区中的依赖,都会安装在目标目录下的一个隔离的 node_modules 目录中。目标目录将包含一个可移植包,可以复制到服务器上并无需额外步骤即可执行。
🌐 Deploy a package from a workspace. During deployment, the files of the deployed package are copied to the target directory. All dependencies of the deployed package, including dependencies from the workspace, are installed inside an isolated node_modules directory at the target directory. The target directory will contain a portable package that can be copied to a server and executed without additional steps.
默认情况下,deploy 命令仅适用于 inject-workspace-packages 设置为 true 的工作区。如果你想在没有“注入依赖”的情况下使用 deploy,请使用 --legacy 标志或将 force-legacy-deploy 设置为 true。
🌐 By default, the deploy command only works with workspaces that have the inject-workspace-packages setting set to true. If you want to use deploy without "injected dependencies", use the --legacy flag or set force-legacy-deploy to true.
当设置 enableGlobalVirtualStore 选项时,pnpm deploy 会忽略它,并始终在部署目录中创建一个本地化的虚拟存储。这保持了部署目录的自给自足和可移植性。
🌐 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.
用法:
🌐 Usage:
pnpm --filter=<deployed project name> deploy <target directory>
如果你在部署前构建项目,也请使用 --prod 选项跳过 devDependencies 的安装。
🌐 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>
在 Docker 镜像中的使用。在构建完你的 monorepo 中的所有内容后,在第二个镜像中执行此操作,该镜像使用你的 monorepo 基础镜像作为构建上下文,或者在额外的构建阶段中执行此操作:
🌐 Usage in a docker image. After building everything in your monorepo, do this in a second image that uses your monorepo base image as a build context or in an additional build stage:
# syntax=docker/dockerfile:1.4
FROM workspace as pruned
RUN pnpm --filter <your package name> --prod deploy pruned
FROM node:18-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY /app/pruned .
ENTRYPOINT ["node", "index.js"]
选项
🌐 Options
--dev, -D
只安装了 devDependencies。
🌐 Only devDependencies are installed.
--no-optional
optionalDependencies 未安装。
--prod, -P
devDependencies 中的包将不会被安装。
🌐 Packages in devDependencies won't be installed.
--filter <package_selector>
--legacy
强制执行旧版部署。
🌐 Force legacy deploy implementation.
默认情况下,pnpm deploy 会尝试从共享锁文件创建一个专用锁文件用于部署。--legacy 标志会禁用此行为,同时也允许在没有 inject-workspace-packages=true 设置的情况下使用部署命令。
🌐 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.
已部署项目中包含的文件
🌐 Files included in the deployed project
默认情况下,部署时会复制项目的所有文件,但可以通过以下 一种 方式进行修改,这些方式会按顺序生效:
🌐 By default, all the files of the project are copied during deployment but this can be modified in one of the following ways which are resolved in order:
- 该项目的
package.json可能包含一个“files”字段,用于列出应被复制的文件和目录。 - 如果应用目录中存在
.npmignore文件,则此处列出的任何文件都会被忽略。 - 如果应用目录中存在
.gitignore文件,则此处列出的任何文件都会被忽略。
配置
🌐 Configuration
forceLegacyDeploy
- 默认:假
- 类型:布尔
默认情况下,pnpm deploy 将尝试从共享锁文件为部署创建专用锁文件。如果将此设置为 true,将使用传统的 deploy 行为。
🌐 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.