What is @nrwl/workspace?
The @nrwl/workspace npm package is part of Nx, which is a set of extensible dev tools for monorepos. It provides a consistent dev experience for different tools and frameworks, and it helps with tasks like running tasks, generating components, and managing dependencies within a monorepo.
What are @nrwl/workspace's main functionalities?
Creating a new workspace
This command sets up a new workspace. It's the first step when starting a project with Nx.
npx create-nx-workspace@latest myworkspace
Generating code
This command generates a new React component within a specified project in the workspace.
nx generate @nrwl/react:component my-component --project=myapp
Running tasks
This command builds a specific application within the workspace.
nx run myapp:build
Dependency Graph
This command visualizes the dependency graph of projects in the workspace, helping to understand the structure and dependencies of the monorepo.
nx dep-graph
Running affected commands
This command runs tests only for the projects affected by the latest changes, optimizing the CI process.
nx affected:test
Other packages similar to @nrwl/workspace
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. Lerna is similar to @nrwl/workspace in that it helps manage monorepos but does not provide the same level of integration with various frameworks or the same CLI experience for code generation and task execution.
What is Nx?
🔎 Nx is a set of Angular CLI power-ups for modern development.
Nx Helps You
Use Modern Tools
Using Nx, you can add Cypress, Jest, Prettier, and Nest into your dev workflow. Nx sets up these tools and allows you to use them seamlessly. Nx fully integrates with the other modern tools you already use and love.
Build Full-Stack Applications
With Nx, you can build full-stack applications using Angular and Node.js frameworks such as Nest and Express. You can share code between the frontend and the backend. And you can use the familiar ng build/test/serve
commands to power whole dev experience.
Develop Like Google
With Nx, you can develop multiple full-stack applications holistically and share code between them all in the same workspace. Nx provides advanced tools which help you scale your enterprise development. Nx helps enforce your organization’s standards and community best practices.
A la carte
Most importantly, you can use these power-ups a la carte. Just want to build a single Angular application using Cypress? Nx is still an excellent choice for that.
Does it replace Angular CLI?
Nx is not a replacement for Angular CLI. An Nx workspace is an Angular CLI workspace.
- You run same
ng build
, ng serve
commands. - You configure your projects in
angular.json
. - Anything you can do in a standard Angular CLI project, you can also do in an Nx workspace.
Getting Started
Creating an Nx Workspace
Using npx
npx create-nx-workspace myworkspace
Using npm init
npm init nx-workspace myworkspace
Using yarn create
yarn create nx-workspace myworkspace
Adding Nx to an Existing Angular CLI workspace
If you already have a regular Angular CLI project, you can add Nx power-ups by running:
ng add @nrwl/schematics
Creating First Application
Unlike the CLI, an Nx workspace starts blank. There are no applications to build, serve, and test. To create one run:
ng g application myapp
The result will look like this:
<workspace name>/
├── README.md
├── angular.json
├── apps/
│ ├── myapp/
│ │ ├── browserslist
│ │ ├── jest.conf.js
│ │ ├── src/
│ │ │ ├── app/
│ │ │ ├── assets/
│ │ │ ├── environments/
│ │ │ ├── favicon.ico
│ │ │ ├── index.html
│ │ │ ├── main.ts
│ │ │ ├── polyfills.ts
│ │ │ ├── styles.scss
│ │ │ └── test.ts
│ │ ├── tsconfig.app.json
│ │ ├── tsconfig.json
│ │ ├── tsconfig.spec.json
│ │ └── tslint.json
│ └── myapp-e2e/
│ ├── cypress.json
│ ├── src/
│ │ ├── fixtures/
│ │ │ └── example.json
│ │ ├── integration/
│ │ │ └── app.spec.ts
│ │ ├── plugins/
│ │ │ └── index.ts
│ │ └── support/
│ │ ├── app.po.ts
│ │ ├── commands.ts
│ │ └── index.ts
│ ├── tsconfig.e2e.json
│ ├── tsconfig.json
│ └── tslint.json
├── libs/
├── nx.json
├── package.json
├── tools/
├── tsconfig.json
└── tslint.json
All the files that the CLI would have in a new project are still here, just in a different folder structure which makes it easier to create more applications and libraries in the future.
Serving Application
Run ng serve myapp
to serve the newly generated application!
You are good to go!
Quick Start & Documentation
Documentation
Books
Videos
Talks
Podcasts and Shows
Misc
Want to help?
If you want to file a bug or submit a PR, read up on our guidelines for contributing.
Core Team