Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ This monorepo is designed around a **bundler-first approach** that prioritizes:

Instead of relying on TypeScript project references, this monorepo uses:

1. **Bundlers (bunchee)** to compile shared packages into optimized dist files
1. **Bundlers (tsdown)** to compile shared packages into optimized dist files
(with `.d.ts` and source maps)
2. **Turborepo** to orchestrate build dependencies and ensure proper ordering
3. **TypeScript** purely for type checking against built artifacts

Expand Down Expand Up @@ -160,7 +161,7 @@ Instead of relying on TypeScript project references, this monorepo uses:
The build process follows this sequence:

1. **Shared packages build first** (`@repo/common`, `@repo/core`)
- Create optimized dist files with type declarations
- Create optimized dist files with `.d.ts` and `.d.ts.map`
- Enable bundler optimizations (tree-shaking, minification, etc.)

2. **Consumer packages check types** (`@repo/web`, `@repo/api`, `@repo/fns`)
Expand All @@ -171,9 +172,46 @@ The build process follows this sequence:
- Ensures proper dependency ordering
- Caches build artifacts for faster subsequent runs

#### tsdown configuration

Each buildable package contains a `tsdown.config.ts` that defines entries and
output behavior. Examples:

```ts
// packages/common/tsdown.config.ts
import { defineConfig } from "tsdown";

export default defineConfig({
entry: "src/index.ts",
outDir: "dist",
target: "es2022",
sourcemap: true,
dts: true,
});
```

```ts
// packages/core/tsdown.config.ts
import { defineConfig } from "tsdown";

export default defineConfig({
entry: {
"db-refs": "src/db-refs.ts",
firebase: "src/firebase.ts",
"utils/index": "src/utils/index.ts",
},
outDir: "dist",
target: "es2022",
sourcemap: true,
dts: true,
platform: "node",
});
```

**Key commands:**

- `pnpm build` - Builds all packages with proper dependency ordering
- `pnpm build` - Builds all packages with proper dependency ordering using
tsdown configs
- `pnpm check-types` - Runs type checking after ensuring dependencies are built
- `pnpm watch` - Continuously rebuilds packages as they change

Expand All @@ -192,7 +230,7 @@ sooner.
### Packages

- [common](./packages/common) Code that is shared across both front-end and
back-end environments simultaneously. Built with bunchee for optimal output.
back-end environments simultaneously. Built with tsdown for optimal output.
- [core](./packages/core) Code that is only shared between server environments,
like cloud functions, containing mostly "core" business logic. Depends on
common.
Expand Down
4 changes: 2 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"@types/react": "^19.1.11",
"@types/react-dom": "^19.0.3",
"del-cli": "^6.0.0",

"madge": "^8.0.0",
"postcss": "^8.5.1",
"tailwindcss": "^4.1.12"
"tailwindcss": "^4.1.12",
"tsdown": "^0.14.2"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"dev": "turbo dev",
"deploy": "firebase deploy",
"watch": "turbo watch build --filter=@repo/core --filter=@repo/fns --filter=@repo/api",
"test": "turbo test -- --watch false",
"test": "turbo test",
"emulate": "firebase emulators:start --project demo-mono-ts",
"format": "biome check --write",
"db:get-indexes": "firebase firestore:indexes > firestore.indexes.json"
Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"check-biome": "biome check",
"check-circular": "madge --circular --extensions ts ./src --ts-config ./tsconfig.json",
"test": "vitest",
"build": "bunchee --sourcemap --target es2022",
"build": "tsdown",
"clean": "del-cli dist tsconfig.tsbuildinfo",
"coverage": "vitest run --coverage"
},
Expand All @@ -28,9 +28,9 @@
},
"devDependencies": {
"@codecompose/typescript-config": "^1.2.0",
"bunchee": "^6.6.0",
"del-cli": "^6.0.0",
"madge": "^8.0.0",
"tsdown": "^0.14.2",
"typescript": "^5.9.2",
"vitest": "^3.0.4"
}
Expand Down
9 changes: 9 additions & 0 deletions packages/common/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "tsdown";

export default defineConfig({
entry: "src/index.ts",
outDir: "dist",
target: "es2022",
sourcemap: true,
dts: true,
});
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"check-biome": "biome check",
"check-circular": "madge --circular --extensions ts ./src --ts-config ./tsconfig.json",
"test": "vitest",
"build": "bunchee --sourcemap --runtime node --target es2022",
"build": "tsdown",
"clean": "del-cli dist tsconfig.tsbuildinfo",
"coverage": "vitest run --coverage "
},
Expand All @@ -26,9 +26,9 @@
"devDependencies": {
"@codecompose/typescript-config": "^1.2.0",
"@types/node": "^24.3.0",
"bunchee": "^6.6.0",
"del-cli": "^6.0.0",
"madge": "^8.0.0",
"tsdown": "^0.14.2",
"typescript": "^5.9.2",
"vitest": "^3.0.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/db-refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { CollectionReference } from "firebase-admin/firestore";
* Here we are using a path alias ~/ to be able to reference the src directory
* from anywhere. This is configured out-of-the box via
* codecompose/typescript-config. This is the responsibility of the bundler
* (Bunchee), because the Typescript compiler does not do this for us. Not all
* (tsdown), because the Typescript compiler does not do this for us. Not all
* bundlers have this feature.
*/
import { db } from "~/firebase";
Expand Down
14 changes: 14 additions & 0 deletions packages/core/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from "tsdown";

export default defineConfig({
entry: {
"db-refs": "src/db-refs.ts",
firebase: "src/firebase.ts",
"utils/index": "src/utils/index.ts",
},
outDir: "dist",
target: "es2022",
sourcemap: true,
dts: true,
platform: "node",
});
Loading
Loading