7/23/2023 0 Comments Npm workspaces dependenciesRunning tasks within multiple packages: Lerna gives us an out-of-the-box solution to run tasks inside multiple packages together using lerna run command. Lerna has some great in-built features which make managing monorepos surprisingly easier. Lerna can rescue us in this situation by doing the heavy lifting of managing the tasks in different packages, versioning, code deployment, etc. Monorepos can have tens if not hundreds of packages, and managing all of them together can become very difficult. Lerna is fast, widely used, and battle tested. To use monorepos well, you need a good monorepo tool, and Lerna is exactly that. If you are interested in setting up a monorepo with Vite, Pnpm, and Typescript you can check out my previous blog here. In this article, we will see how we can set up a monorepo with Lerna and Npm workspaces. ![]() Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository. Lerna is a powerful tool that can be used to manage and publish monorepos in Javascript/Typescript projects. That will create a new package.Monorepos lets you manage multiple repositories into one single repository but managing and publishing them can be very tedious as the repositories grow. To initialize the project with defaults, run this command in the project folder: npm init -y Paste the following into the file and save it:.To prevent build folders and files from being checked in: Create a new folder for a new monorepo / workspace project:Ĭd workspace-js Step 3.Change to a parent folder for all of your projects.Though on occasion you might want to upgrade them to the latest version. That command installs the latest version of npm and mocha - a test automation utility.īecause the packages are installed globally, you won’t need to do this again for new projects. Run the following (only use sudo in the front if you have rights issues):. ![]() Upgrade to the latest version of npm and install the mocha testing framework globally: If you don’t have npm installed, click here. You must ensure that you have the latest version of npm installed in order to use workspaces. Install the latest npm and mocha globally If you've ever wrestled with npm link to test one local package that depends on another local package, you may appreciate workspaces as an alternative. We also refer to these packages being auto-symlinked during npm install as a single workspace, meaning it's a nested package within the current local file system that is explicitly defined in the package.json workspaces configuration. Automating the linking process as part of npm install and avoiding manually having to use npm link in order to add references to packages that should be symlinked into the current node_modules folder. This set of features makes up for a much more streamlined workflow handling linked packages from the local file system. Workspaces is a generic term that refers to the set of features in the npm cli that provides support to managing multiple packages from your local file system from within a singular top-level, root package. ![]() What is an npm workspace?įrom the online documentation (see references at the end of this article): These instructions were written for a Mac. ![]() With the latest versions of npm you no longer need third-party tools to manage your packages in one repo. In this article, I show you how to set up a JavaScript monorepo using npm workspaces.
0 Comments
Leave a Reply. |