Monorepos and cross package development. To use src/ or dist/?

Viewed 666

My fellow yarn workspace typescript monorepo-nians,

Question: When you are working within a monorepo are you able to import and use source code across packages or do you rely on the build steps artifact to use a package from a separate package?

For example you have this folder structure

packages/
  frontend/
  api/
  dateTimeHelpers/
    src/
    dist/

Both frontend/ and api/ have a dependency on the dateTimeHelpers package

frontend/ + api/ package.json

dependencies: {
  dateTimeHelpers: "1.0.0"
}

You are running frontend , hot reloading and the like and want to add a function to the dateTimeHelpers package and use said function within the frontend package

Do you have to compile the dateTimeHelpers package (aka frontend is using the dateTimeHelpers/dist folder), or will your frontend import the src code from dateTimeHelpers and compile it on the fly (or just when it builds)?

All the packages are written in TypeScript and require a build step in order to be used.

Thank you for entertaining this. I am having a hard time seeing what I should be shooting for. I have dist usage working - but I would like to not be running two build commands or have to build ad-hoc when developing.

Cheers

1 Answers

I am going to close this question, because I believe that this is the proper behavior to fix it!

Seems that even within the TS community, there is confusion on this.

When you build within frontend/ it should know that dateTimeHelpers is a dependency and subsequently build that.

So this means that each package is always working out of dist/ but webpack knows to compile across packages.

https://github.com/TypeStrong/ts-loader/releases/tag/v8.0.0

https://github.com/TypeStrong/ts-loader/issues/1114

Related