Logo

dev-resources.site

for different kinds of informations.

Creating a scalable Monorepo for Vue - Intro

Published at
1/14/2025
Categories
monorepo
vue
yarn
nx
Author
nagell
Categories
4 categories in total
monorepo
open
vue
open
yarn
open
nx
open
Author
6 person written this
nagell
open
Creating a scalable Monorepo for Vue - Intro

Hello world,

which means that this is my first article β€” first of many β€” as I intend to write a series on creating a monorepo structure for Vue.

Β 

What problem are we trying to solve?

Vue has become quite popular over the years, and more mid-size companies β€” and even some big names like Nintendo, Adobe, or Gitlab to name a few β€” are adopting it. Sometimes, they even choose it as the primary Framework for their products. That's why growing codebases containing many Vue packages are becoming common.

Juggling with projects and packages, publishing, updating, and dealing with the consequences of postponing the last step longer than we intended, due to fast-paced workflows - many were already there, or are right now.

This raises the question:

Is there a good alternative and what are the trade-offs?

In this series, I'll try to answer these questions, as well as provide one of the solutions which you can see complete in this template. Feel free to use it as a base to kickstart your project or simply try it out.

If you have any questions, feel free to leave a comment or add a suggestion in the sample repo.

Β 

Monorepo

There is at least one good alternative on which we will focus as it's definitely a mature and battle-proven one - monorepo.

The simple explanation is that we put everything into one directory. That's it? Well... not exactly. There are many additional possibilities, but let's start with the easy stuff.

Β 

One repo, but not much more...

In the simplest form, it means that we create one repository with a bunch of sub-directories for our projects and libraries (packages) and that's it. The rest stays as it is: pushing to the origin, publishing with npm or Lerna. Maybe even with semantic-release if you already made some optimization of the process.

Pros:

  • Many projects in one place -> less opened windows
  • Better overview of your team's work

Cons:

  • More branches -> potential chaos in the git tree

Β 

Add workspace

But what about managing external dependencies and consuming your libraries (packages)?

If you don't want to go to every project and update dependencies manually you should consider so-called workspaces. More about them in the next article in the series. In short, they will allow you to update more, maybe even all dependencies at once, and still keep full control over your projects, when some more granular interference will be required.

Pros:

  • Faster update of dependencies for many projects at once
  • Less juggling with versions

Cons:

  • Requires updating more projects at once if they are tied to the same dependency. They can still be split but it's somehow contrary to the goal

Β 

Add direct connection of dependencies

The workspaces are allowing us to manage external and internal dependencies way more easily. But what if I told you that you can directly use your other projects without even building them, not even mentioning publishing? With correct typescript configuration, you can even
have types and intellisense still working. That is what you can achieve by connecting other of your libraries (previously packages) in your package.json like this:

{
    "name": "@monorepo/app_1",
    "version": "1.0.0",
    "type": "module",
    "scripts": {
        // ...
    },
    "dependencies": {
        "@monorepo/commons": "*",
        "@monorepo/ui": "*"
    },
    // ...
}
Enter fullscreen mode Exit fullscreen mode

Notice the stars instead of version numbers. These mean that we are using whatever version is the newest. In our case, it's always the local one.

Pros:

  • Always the current version (also while developing in branches)
  • No need to publish libraries as packages and reinstall them
  • No local linking required to try out new library versions

Cons:

  • After a merge, dependencies might differ, potentially causing problems

This caveat can be mitigated with good test coverage and TypeScript running automatically through the complete codebase on the server before every build (which I highly recommend, regardless; ex. on the dev branch). This can be easily automated with husky).

Β 

If you want to know how to create such structure with Vue check out other tutorials in the series. If you prefer testing things on your own - try this template.

nx Article's
30 articles in total
Favicon
Creating a scalable Monorepo for Vue - Workspaces
Favicon
Creating a scalable Monorepo for Vue - Intro
Favicon
Run Storybook with NX Expo and React Native Paper
Favicon
Nx + TypeORM + NestJS + Migrations
Favicon
Why Monorepo Projects Sucks: Performance Considerations with Nx
Favicon
Convert a ReactJS app from Vite to Nx
Favicon
Nx 20: Exploring the new TS preset and TypeScript project references
Favicon
How to deploy affected NX projects to AWS S3 using Github Actions
Favicon
Angular Addicts #30: When to use effects, Angular DI features, request caching & more
Favicon
The Dotnet, Nx, AnalogJs (Angular) Stack is here - Part 1
Favicon
The Dotnet, Nx, AnalogJs (Angular) Stack is here - Part 2
Favicon
Semantic versioning of NestJS and Angular applications in the NX monorepository
Favicon
Hybrid NestJs Microservice Responding to Both HTTP and gRPC Requests
Favicon
Create a CI Workflow with Minimal Boilerplate Using Nx, Docker, and GitHub Actions
Favicon
Creating a web3 DApp with a NX Monorepo
Favicon
NX Playwright integration as a package in mono repo
Favicon
How to setup the project in micro frontend architecture
Favicon
The Stages of an Angular Architecture (Angular Global Summit)
Favicon
What is a Monorepo
Favicon
πŸ‘₯ Reproducible Nx Workspace with HugeNx’s Conventions
Favicon
πŸ’ Cherry-Picked Nx v19 Updates
Favicon
πŸ’ Cherry-Picked Nx v19.1 Updates
Favicon
πŸ’ Cherry-Picked Nx v18.3 Updates
Favicon
You might not be lazy loading properly in Angular. Pitfall of barrel files.
Favicon
🩹 Nx Crystal Plugin Picking the Essentials
Favicon
πŸ’ Cherry-Picked Nx v18.1 Updates
Favicon
Monorepos - Why Speed Matters
Favicon
πŸ’ Cherry-Picked Nx v18.2 Updates
Favicon
Nx adoption guide: Overview, examples, and alternatives
Favicon
Creating Nx Workspace with Eslint, Prettier and Husky Configuration

Featured ones: