And it's supported in all the major package managers, npm, yarn, pnpm, bun. All these are built in. All these package managers have built-in support for workspaces.
What a workspace is if you've never used it before, is just an entry inside of your package JSON that points to a location where you would like to tell your package manager, these are subprojects within this workspace.
So in this case, we have two locations that we want to be considered workspaces, or part of this workspace, we have an app, so we're going to list every single folder inside of apps. And then we have packages so we can split out what's considered top-level app level kind of projects and packages that get used within inside those apps.
When we go ahead and install all of our dependencies, we actually are able to tell each one of those packages, I would like to use library ABC or one, two and three, reference them using a different syntax.
Instead of giving a version number, we're just going to say workspace. And node will act, your node in your package manager will actually sim link them to the node modules. Now all your packages get resolved as if they're coming from node modules, and if they're just your regular old npm package.
So that's great networks fine, but it doesn't solve everything you just yet. And that's where we get to project references. Because if we have all these things sim linked into our node modules, how do we make sure that those types are included? And how do we make sure that we know where all these packages are coming from?
Project references? Anyone heard project references before? Again, I'm, I'm acting as if this is live, and I can see you. Chances are, most people haven't heard of project references. It was something that came out in TypeScript three, and I had only heard of it last year.
Project references are a way to reference other projects in a TypeScript project. Pretty, pretty self-explanatory. So if we think back to our pain point of using path aliases, remember, it is still a lie. These don't actually solve any of our pain points. These do not make TypeScript fast.
However, this can make TypeScript fast, make sure I'm using my words correctly, it can make your TypeScript fast. What we're doing here is instead of pointing to an actual project, like into an actual entry point like we did with paths, we're actually pointing back to a directory that has a TS config in there.
So while this looks very similar, it's fundamentally a different approach to how we can have TypeScript pre everything in isolation. So the path property is actually a reference to another TS config. And a project that you want to just or any other config file that you want to tell TypeScript, this is a sub project, this is something that is going to be built, isolated from everything else.
References, everything, all this just kind of works. And let's go back to our editor. And hey, look, our build from before actually completed, you can see it took about 106 seconds. First build took about 109. So slight difference.
Comments