pnpm 部署
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.
使用方式:
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>
使用於 Docker 映像中。 在您的 Monorepo 中組建完所有內容後,請在第二個使用 Monorepo 基本映像作為建置內容的影像中或在其他組建段中執行:
# 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
Only devDependencies
are installed regardless of the NODE_ENV
.
--no-optional
不安裝 optionalDependencies
。
--prod, -P
Packages in devDependencies
won't be installed.
--filter <package_selector>
已部署完成的專案中包含的檔案
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:
- The project's
package.json
may contain a "files" field to list the files and directories that should be copied. - If there is an
.npmignore
file in the application directory then any files listed here are ignored. - If there is a
.gitignore
file in the application directory then any files listed here are ignored.