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.
默认情况下,部署命令仅适用于将 inject-workspace-packages
设置设置为 true
的工作区。如果你想在没有 "注入的依赖" 的情况下使用部署,请使用 --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
.
用法:
¥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 --from=pruned /app/pruned .
ENTRYPOINT ["node", "index.js"]
选项
¥Options
--dev, -D
仅安装 devDependencies
。
¥Only devDependencies
are installed.
--no-optional
optionalDependencies
未安装。
¥optionalDependencies
are not installed.
--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" 字段来列出应复制的文件和目录。¥The project's
package.json
may contain a "files" field to list the files and directories that should be copied. -
如果应用目录中有
.npmignore
文件,则将忽略此处列出的任何文件。¥If there is an
.npmignore
file in the application directory then any files listed here are ignored. -
如果应用目录中有
.gitignore
文件,则将忽略此处列出的任何文件。¥If there is a
.gitignore
file in the application directory then any files listed here are ignored.