zustand Auto Generating Selectors
https://docs.pmnd.rs/zustand/guides/auto-generating-selectors
ts-pattern 替换匹配组件代
swr
TypeScript在monorepo项目中实现即时更新
https://colinhacks.com/essays/live-types-typescript-monorepo
monorepo docker
项目名:my-project
docker-files/my-project
这个是为了针对单项目多服务的情况,所有 docker 都可以写到这里,不用单独放在子模块里面了
镜像最好已经安装了 pnpm
# 基础镜像
FROM node:18.18.2pnpm8.5
# 设置工作目录
WORKDIR /usr/src/app
# 安装 [email protected]
RUN npm config set registry https://registry.npmmirror.com/
RUN npm install -g [email protected]
# 复制项目代码
COPY . .
# 裁剪相关项目
RUN turbo prune my-project --docker
# 安装依赖
RUN cp -r out/json/ .
RUN cp out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install
# 复制源码
RUN cp -r out/full/ .
# build正式环境 --env-mode=loose这里采用松散模式,不然没法传递环境变量
RUN pnpm turbo run build --env-mode=loose --filter=my-project...
# 进入对应项目准备发布
WORKDIR /usr/src/app/apps/my-project
# 静态资源上传到cdn
RUN pnpm cdn\_upload
# 暴露内部端口号
EXPOSE 5000
# 起服务
ENTRYPOINT ["pnpm"]
CMD ["production"]
turb 使用
给子模块安装依赖
pnpm install jest --save-dev --recursive --filter=web --filter=@repo/ui --filter=@repo/web
将依赖关系保持在同一版本
https://turbo.build/repo/docs/crafting-your-repository/managing-dependencies#keeping-dependencies-on-the-same-version
pnpm up --recursive typescript@latest
tsconfig.json
https://turbo.build/repo/docs/crafting-your-repository/creating-an-internal-package#add-a-tsconfigjson
{
"extends": “../../base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
根据 TypeScript 规范, include 和 exclude 键不会从基本配置中继承,因此您在此处包含了它们。
并行执行命令
https://turbo.build/repo/docs/crafting-your-repository/running-tasks#running-multiple-tasks
turbo run lint test build
任务模式
https://turbo.build/repo/docs/crafting-your-repository/configuring-tasks
指定缓存
https://turbo.build/repo/docs/crafting-your-repository/configuring-tasks#specifying-inputs
既可以并行运行,又能在依赖包的代码发生变化时正确地检测到错误
https://turbo.build/repo/docs/crafting-your-repository/configuring-tasks#dependent-tasks-that-can-be-ran-in-parallel
重点transit
过滤包
turbo build --filter=@repo/ui
强制忽略缓存
--force
https://turbo.build/repo/docs/crafting-your-repository/caching#overwriting-a-cache
watch
监听模式