turborepo 命令行
shell
# 安装
pnpm add turbo -D
# 执行任务(全部项目 执行 build 脚本)
turbo run build
# 执行任务(在 turbo.json 中定义 build 任务,然后为 @scope/web 项目执行 build 脚本)
turbo run @scope/web#build # 等同于 turbo build --filter=@scope/web
turbo run web#build docs#lint配置文件
pnpm-workspace.yaml
yaml
packages:
- "apps/*"
- "packages/*".gitignore
text
.turboturbo.json
json
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": [".next/**", "!.next/cache/**"]
},
"check-types": {
"dependsOn": ["^check-types"]
},
"dev": {
"persistent": true,
"cache": false
}
}
}package.json
json
{
"scripts": {
"dev": "turbo dev",
"dev:admin": "pnpm -F @meco/admin run dev",
"postinstall": "pnpm -r run stub --if-present" // pnpm install 的时候就会执行该命令,遍历所有的子包( -r ),如果存在 package.json 且存在 stub 命令则执行(--if-present)
},
"packageManager": "[email protected]+"
}命令行
shell
# package.json
# "dev:admin": "pnpm -F @meco/admin run dev"Docker 构建
dockerfile
# 构建:当前项目代码
FROM 1ms.run/node:23-alpine AS base
WORKDIR /app
COPY . .
RUN npm config set registry https://registry.npmmirror.com
RUN npx -y turbo prune @meco/admin --docker
FROM 1ms.run/node:23-alpine AS builder
WORKDIR /app
ARG VITE_DEPLOY_ENV=prod
RUN npm config set registry https://registry.npmmirror.com
RUN npm install -g pnpm turbo
# install the dependencies
COPY --from=base /app/out/json/ .
RUN pnpm install
# Build the project
COPY --from=base /app/out/full/ .
RUN pnpm turbo build -- --mode $VITE_DEPLOY_ENV
FROM 1ms.run/nginx:1.21 AS runner
COPY --from=builder /app/apps/admin/dist /usr/share/nginx/html
COPY ./apps/admin/conf/nginx.conf /etc/nginx/
CMD ["nginx", "-g", "daemon off;"]