To visualize these "affected libraries", use the nx affected:graph command, in this example below we've added a second-shared lib which is also used in next-app. nx affected -target=next-app will figure out which tasks to run, and only run those tasks. To handle this, NX has the affected command. When you run nx test next-app, you are telling Nx to run the next-app:test task plus all the tasks it depends on.įor a small project this is okay, however for a large project you really only want to run the tests for the files and changes you've made to the app. Here you can see the process of importing our new shared library, and using it in our Next.js app. The beauty of this pattern is that if you change ui-shared, it will rebuild other apps that use it, whereas, if you make a change in next-app NX won't rebuild ui-shared. Running this command generates a new ui-shared library, which can be used by multiple apps. Automatic project dependency managementĬreate a new NX project, with a Next.js application.Ability to build and test only what you need to.Integrations and plugins for many platforms (including a VSCode Plugin).Some of the most acclaimed features of NX are as follows: NX is one of the most advanced build systems available and offers some incredibly powerful features to take your codebase to the next level. You don't want to add additional dependencies.Running commands against multiple packages from the top level repository, e.g.Workspaces provides two basic features, as for the most part Workspaces are just code collocation with the ability to run projects from one terminal in conjunction. Workspace is a generic term that refers to a set of features in the NPM cli which adds support for managing multiple packages from the root of the repository, NPM workspaces allow you to deduplicate node modules and run commands against multiple projects at the same time.īelow is an example structure of a repository using NPM workspaces Making a Monorepo for a fullstack JavaScript code base is easier than ever, the easiest solution with no additional dependencies is NPM Workspaces, and the other two solutions we will cover are NX and TurboRepo. Learning Curve - Some tools to manage a Monorepo add technical complexity, especially during the setup.Slower IDE Performance - For large Monorepos it's possible to have a slower IDE performance due to the increased number of files, this can slow down imports, intellisense and other IDE features.There aren't many downsides to using a Monorepo, but there are some that are worth mentioning: Deduplication of node modules - Node modules are the computational equivalent of a black hole already, so any deduplication or help here is always appreciated.A single CI/CD pipeline - There is no need for multiple pipelines in each application as we can handle it in one centralized place.Single source of truth - As all changes to the repo are atomic, there won't be a situation where one team is working with outdated legacy code.Build and Development Caching - Some tools like NX and Turborepo allow for efficient rebuilds to allow rebuilding only changed packages. Visibility - Everyone in the organisation can see all the code, improving cross-team collaborations and communication.Consistency - It's possible to share UI modules, documentation and other such shared packages.There are a number of important benefits to using a Monorepo (with a Smart Build System). Recently a common software development practice is to have a full stack JavaScript application, this leads to many developer teams believing they have a Monorepo "Because all of my code is in the same repository".Ī monorepo is far more than just code collocation, we'll address the benefits, drawbacks and showcase two industry leading Smart Build Systems. A monorepo is a consolidated repository containing the source code of multiple projects, which are commonly managed by independent teams and also often share common packages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |