DEV Community

Discussion on: Exploring the Monorepo #2: Workspaces (npm, pnpm)

 
panta82 profile image
panta82

Once again, AFAIK.

There is one thing you can experiment with that I use in one project. You can declare a local npm module, that lives in the same monorepo with the rest of the code.

The declaration would look like this:

"dependencies": {
  "analytics": "file:libs/analytics",
}
Enter fullscreen mode Exit fullscreen mode

Then in lib/analytics define a package.json and tsconfig with the settings you like. Build.

Then when you do import x from 'analytics'; is should find the compiled code from libs/analytics/dist. Then add npm hooks to run compilation on post npm-install or whenever you need depending on your workflow.

I haven't tried this, but maybe it's worth a shot.

Thread Thread
 
jonlauridsen profile image
Jon Lauridsen • Edited

Yeah that makes sense. It's the "npm hooks to run compilation" that bothers me, because it sounds a lot like I'll be fighting the tools to do things they weren't meant for. But it might be the only way 😬

Thanks for the insights.