https://github.com/arthurhub/ts-project-reference
https://github.com/arthurhub/ts-project-reference
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/arthurhub/ts-project-reference
- Owner: ArthurHub
- Created: 2024-10-16T20:06:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-07T18:25:00.000Z (over 1 year ago)
- Last Synced: 2025-05-14T04:36:02.467Z (about 1 year ago)
- Language: TypeScript
- Size: 308 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Code sample for my [Sharing Code in TypeScript and Project References](https://theartofdev.com/2024/11/07/sharing-code-in-typescript-and-project-references/).
### tl;dr
- Strategies for sharing code and how they integrate within the TypeScript ecosystem.
- [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) enable code sharing across multiple TypeScript projects within a single codebase (monorepo), offering modularization, dependency management, and incremental builds.
- The [simple](https://theartofdev.com/2024/11/07/sharing-code-in-typescript-and-project-references/#3-esm) use of Project References is straightforward but can result in cumbersome import paths like `../../../../../libs/dist/data-access/loader/common.js`, which expose the project's internal folder structure.
- This post explores solutions to the import path issue, balancing complexity and elegance:
- [TypeScript `paths` aliasing](https://theartofdev.com/2024/11/07/sharing-code-in-typescript-and-project-references/#4-esm-with-paths-aliases) adds complexity by requiring extra tooling for runtime import resolution.
- [Bundlers](https://theartofdev.com/2024/11/07/sharing-code-in-typescript-and-project-references/#5-esm-with-bundler), while somewhat cumbersome, largely resolve these issues and provide production deployment tools.
- [`npm workspaces`](https://theartofdev.com/2024/11/07/sharing-code-in-typescript-and-project-references/#6-esm-with-npm-workspaces) mimic external `npm` dependencies using symlinks in `node_modules`, addressing import paths without aliasing or extra tooling and enabling package export management for better modularization.
- In conclusion, TypeScript [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) combined with [npm workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces) provide an optimal solution for multi-project code sharing within a single codebase in TypeScript.
[...continue reading](https://theartofdev.com/2024/11/07/sharing-code-in-typescript-and-project-references/)