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.
用法:
¥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
无论 NODE_ENV
为何,仅安装 devDependencies
。
¥Only devDependencies
are installed regardless of the NODE_ENV
.
--no-optional
optionalDependencies
未安装。
¥optionalDependencies
are not installed.
--prod, -P
devDependencies
中的软件包将不会被安装。
¥Packages in devDependencies
won't be installed.
--filter <package_selector>
已部署项目中包含的文件
¥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.