Table of content
* Intro to Nx
- Concept of Nx
- Pros and cons
- Compare Nx to other alternatives
* Demo
- How to config and use Nx in monorepo
- Inherit the caching benefits of Nx
- Write and apply a Nx task executor (ft. keystone-6 CLI)
Introduction to NX build system
Nx is a smart, fast and extensible build system with first class monorepo
support and powerful integrations.
Goals:
- Speed up your existing workflow with minimum effort.
- Provide a first-rate developer experience (DX) no matter the size of the
repo.
Main concepts
> Nx is like the VSCode of build tools. The core of Nx enables project and
task graph creation and analysis, orchestration and execution of tasks,
computation caching, and code generation. Nx plugins extend this
functionality and are built on top of the underlying Nx Devkit
https://nx.dev/plugin-features/create-your-own-plugin#create-your-own-plugin
Main concepts
- Based on the concept of a monorepo which includes many projects
- Incremental builds
- Ability to manage dependencies (and workspace visualizations)
- Reducing the need for duplicative code (especially in setup)
- Provide tools(aka NX plugins) to help enforce best practices
- Generators: scaffolding source, updating your configuration files
- Executors: perform actions on dev’s code; can include building, linting, testing,
serving…
Pros of NX
● Improved Productivity
● Scalability
● Consistency
● Customization: custom plugins, generators, and executors
Cons of NX
● Steep Learning Curve
● Higher Overhead: The added complexity of NX Build System can result in a
higher overhead, requiring more time and resources to set up and maintain
compared to simpler build systems.
Comparison: Nx vs alternatives
1. Yarn workspaces, Lerna
Nx and Yarn workspaces are complementary, so it makes sense to use
both in some situations
Therefore, they are also complementary.
- YW main features: linking dependencies, unifize modules,...
- Lerna main features: bootstrapping and publishing library with npm
registry, npm version tooling,..
Comparison: Nx vs Turborepo
2. Nx Vs Turborepo (according to the article https://nx.dev/more-concepts/turbo-
and-nx)
Same features:
- Incremental Adoption
- Project graph visualization
- Detecting affected projects/packages
- Local task coordination
- Local computation caching
- Distributed computation caching
Comparison: Nx vs Turborepo
Not available on Turborepo:
- Distributed task execution
- Editor support
- Separate configurations
- Transparency terminal output
- Customizable workflow plugins
- Nx has bigger community
Comparison: Nx vs Turborepo
Performance:
Nx is better.
See:
- https://github.com/vsavkin/large-monorepo/#benchmarking-nx-turbo-and-lerna
- https://nx.dev/more-concepts/turbo-and-nx#tech-and-performance
Nx uses NodeJS with C++ modules and tree-diffing algo (like React.js) to restrict almost
all unnecessary IO tasks.
Turborepo uses Golang. All the caches will blow up on every update if not match cache
hashes.
these projects could include the main application, libraries, and any other related projects.
Improved Productivity: The modular architecture of NX Build System allows for faster and more efficient development, making it easier to build and maintain large projects.
Scalability: With support for monorepos, NX Build System can handle large codebases with multiple projects, making it easier to manage dependencies and share code between projects.
Consistency: By providing a consistent workflow and set of tools, NX Build System can help enforce best practices and ensure that all code is written and structured consistently.
Customization: NX Build System can be easily customized using plugins, generators, and custom schematics, allowing developers to tailor the build process to their specific needs.
Steep Learning Curve: Due to its complexity, NX Build System can have a steep learning curve, especially for developers who are new to monorepo architectures or the Angular framework.
Higher Overhead chi phi cao: The added complexity of NX Build System can result in a higher overhead, requiring more time and resources to set up and maintain compared to simpler build systems.