NiGhTTraX / ts-monorepo

Template for setting up a TypeScript monorepo
MIT License
1.5k stars 169 forks source link

Understanding why `foo` is mapped to `foo/src` in the `nextjs` branch #313

Closed PaulRBerg closed 1 year ago

PaulRBerg commented 1 year ago

I was looking at the nextjs branch, specifically at the tsconfig.json file in packages/nextjs:

https://github.com/NiGhTTraX/ts-monorepo/blob/0ad8608a368042a7e3b45aece446c667d5087637/packages/nextjs/tsconfig.json#L11-L14

And I'm trying to understand why you have remapped foo to foo/src, and components to components/src. Shouldn't these packages be built and loaded from dist? Or did you have to do this because Next.js doesn't support TypeScript project references?

I also don't understand how the external dependencies of foo and components are resolved when building the Next.js app. Does this rely upon node_modules being hoisted at the root?

Side note: would you like to enable GitHub Discussions in this repository? I would have created a discussion instead of a repo.

NiGhTTraX commented 1 year ago

@PaulRBerg the nextjs branch is quite old , the latest NextJS example is under apps/nextjs.

Every example in apps/* uses path aliases to load dependencies from the monorepo source code, instead of from build artifacts, both when building and when running e.g. dev servers. This doesn't rely on node_modules symlinks, but on TypeScript's resolution mechanisms, and makes "Go to definition" work as expected.

Examples in packages/* do use node_modules symlinks to build artifacts, but only when building. See also https://github.com/NiGhTTraX/ts-monorepo/tree/1ee87c100a3bd65ebae4eb000c76354532f70c09#packages-vs-apps.