What is @nrwl/js?
@nrwl/js is a package from the Nx suite of tools that provides utilities for building JavaScript libraries and applications. It is designed to work seamlessly within the Nx workspace, offering features like project scaffolding, dependency management, and build optimization.
What are @nrwl/js's main functionalities?
Project Scaffolding
This command generates a new JavaScript library within an Nx workspace. It sets up the necessary configuration files and directory structure to get started quickly.
nx generate @nrwl/js:lib my-lib
Dependency Management
This command visualizes the dependency graph of the projects within the Nx workspace. It helps in understanding how different projects are interconnected.
nx dep-graph
Build Optimization
This command builds the specified JavaScript library, applying various optimizations to ensure efficient output. It leverages Nx's caching and incremental build features to speed up the build process.
nx build my-lib
Other packages similar to @nrwl/js
lerna
Lerna is a tool for managing JavaScript projects with multiple packages. It optimizes the workflow around managing multi-package repositories with git and npm. Compared to @nrwl/js, Lerna is more focused on managing multiple packages rather than providing a full suite of development tools.
turborepo
Turborepo is a high-performance build system for JavaScript and TypeScript codebases. It offers features like remote caching, parallel execution, and incremental builds. While @nrwl/js is part of the Nx ecosystem and integrates deeply with it, Turborepo is a standalone tool that can be integrated into various workflows.
Nx: Smart, Fast and Extensible Build System
Nx is a next generation build system with first class monorepo support and powerful integrations.
This package is a JavaScript/TypeScript plugin for Nx.
Getting Started
Creating an Nx Workspace
Using npx
npx create-nx-workspace
Using npm init
npm init nx-workspace
Using yarn create
yarn create nx-workspace
The create-nx-workspace
command will ask you to select a preset, which will configure some plugins and create your applications to help you get started.
? What to create in the new workspace (Use arrow keys)
❯ apps [an empty workspace with no plugins with a layout that works best for building apps]
core [an empty workspace with no plugins set up to publish npm packages (similar to yarn workspaces)]
ts [an empty workspace with the JS/TS plugin preinstalled]
react [a workspace with a single React application]
angular [a workspace with a single Angular application]
next.js [a workspace with a single Next.js application]
nest [a workspace with a single Nest application]
express [a workspace with a single Express application]
web components [a workspace with a single app built using web components]
react-native [a workspace with a single React Native application]
react-express [a workspace with a full stack application (React + Express)]
Select the preset that works best for you
Adding Nx to an Existing Monorepo
Run:
npx add-nx-to-monorepo@latest
Documentation & Resources
A few links to help you get started: