How can I include a typescript folder outside the project root in the build and alias the path
Asked Answered
C

1

0

I have a folder of typescript code that I want to share between two TS projects in a repo. It's various helper classes and DB models. They don't have unifying logic of their own, so it doesn't make sense to make them into a library.

If I include the common folder in the paths config (link), or the rootDirs (link), the root of the output folder changes to the most common path (link). Instead, I want to keep each project folder as output root, and instead build the common folder into that root of each project.

I imagine that if I alias the common folder JS destination using paths, I can use it in my imports.

How do I achieve this? (similar question).

input:

/project1/**/*.ts
/project2/**/*.ts
/common/**/*.ts

output project1:

/project1/**/*.js
/project1/common/**/*.js

output project2:

/project2/**/*.js
/project2/common/**/*.js
Champ answered 4/4, 2023 at 9:25 Comment(0)
C
0

If you want to make a dependency package, just make a dependency package

If you use workspaces feature of yarn/pnpm/whatever, you may make multiple packages at once, which works great with a bunch of dependent packages

If you use link feature of yarn/pnpm/whatever, you may link your package as a dependency of another your package locally. See bundled dependencies on how to include it into build

Cowfish answered 4/4, 2023 at 11:56 Comment(2)
Could you elaborate or show an example of how to do this?Olvan
@Olvan pnpm.io/workspacesCowfish

© 2022 - 2024 — McMap. All rights reserved.