8/31/2023 0 Comments Monorepo npm workspaces![]() ![]() The first thing that we need to do for our setup is, create a new project which we will call "pnpm-monorepo" you can of course name it whatever you want to. To follow along you must have pnpm and node installed in your machine. Now that we have an idea about what monorepos are and what problems they solve, let's dive right into the setup and see how we can set up a basic monorepo with pnpm workspaces. Monorepos can significantly improve this workflow by packaging both of these projects into a single repository and importing components directly from the workspace instead of importing them from the cloud. Since lerna works with npm, let’s take a look at how it implements monorepos. The problem with this type of workflow is every time we will make any new changes to the shared package, we will have to publish the app again to the npm registry for the consumer app to get the latest changes and use them. The two most popular solutions are Yarn workspaces and lerna. Since Nx will be used for running operations across the entire monorepo workspace we’re going to install it at the root level package.json. Workspaces are managed by your package manager, so make sure youve set that up first. Each app and package you add to your monorepo will be inside its own workspace. Then the consumer app can install it from the npm registry and use it how we import and use React, Tailwind, Material-UI and other packages. Workspaces are the building blocks of your monorepo. Using turbo I can run both backend and frontend. One way to work with this type of project is a multi-repo approach where we create two separate repositories and host them at the npm registry. Monorepo NestJS + React root npm install workspace Hi Im working on a small project that includes NestJS and Vite + React. Main: This is going to be our main project which will be the consumer of our Shared package. Shared: This will have all our shared components that can be used by different projects. Let's consider an example where we are building an application and we have two projects inside of it: Monorepo is a repository that contains many distinct projects which are somewhat dependent on each other but they are logically independent and different teams can work on them in isolation. In this article, we will talk about how to set up a monorepo with Vite, Typescript, and pnpm workspaces.īefore we jump into the setup, we first need to understand what is a monorepo and why should we care about it. In this article, Jorge explains why they’re a great tool and how to create your first monorepo using Yarn with basic npm scripts, and add the required dependencies for each app. But I only want to have the node_modules that are required in from the nestjs production build.Monorepos are hot these days and it can significantly improve the development workflow and productivity among teams. Yarn workspaces let you organize your project codebase using a monolithic repository (monorepo). The problem here: node_modules contains all dependencies from all apps and packages. ![]() After that, I build and copy only the nestjs server dist folder, package.json and node_modules. This is necessary, that the server package finds the local shared package. In the builder, I’m copying the whole monorepo and installing all dependencies. RUN cd apps/nestjs-server & npm run buildĬOPY -from=builder /home/node/apps/nestjs-server/package*.json /home/node/ĬOPY -from=builder /home/node/apps/nestjs-server/dist/ /home/node/dist/ĬOPY -from=builder /home/node/node_modules/ /home/node/node_modules/ This is how it looks: FROM node:16-alpine AS builder I got this working successfully, with a Dockerfile in the repo root. The packages are set up with Typescript project references. This is working well: I only have one copy of nodemodules at the root and all the packages share it. I created ts-npm-monorepo as a bare-bones example for how to set up a monorepo with Typescript using only NPM Workspaces. What I want is to have the nestjs server deployed on fly. This one was a bit simpler but was using yarn in the examples. I have a question regarding my setup: I have a mono repository with npm workspaces. I was just playing around with fly.io and I’m quite impressed how everything just works.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |