This PR updates examples in `.md` files (both docs and blog posts) to use positional args. Nx 20 changes the position arg to be either `directory` for apps/libs or `path` for artifacts (e.g. components). So before you'd do this: ``` nx g app myapp --directory=apps/myapp nx g lib mylib --directory=libs/mylib nx g lib mylib --directory=libs/nested/mylib nx g lib @acme/foo --directory=libs/@acme/foo --importPath=@acme/foo nx g component foo --directory=libs/ui/src/foo --pascalCaseFiles ``` Will now be simplified to ``` nx g app apps/myapp nx g lib libs/mylib nx g lib libs/nested/mylib nx g lib libs/@acme/foo # name and import path are both "@acme/foo" nx g component libs/ui/src/foo/Foo ``` For cases where `name` and `importPath` need to be changed, you can always manually specify them. ``` nx g lib libs/nested/foo # name is foo nx g lib libs/nested/foo --name=nested-foo # specify name with prefix nx g lib libs/@acme/foo --name # use "foo" as name and don't match importPath nx g lib libs/@internal/foo --importPath=@acme/foo # different importPath from name <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
2.5 KiB
The workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.
Creating Local Generators
Codifying your organization's best practices into local generators is a great way to ensure that the best practices are easy to follow and implement. Running nx g @nx/plugin:plugin packages/feature will create a local plugin with a generator which is written the same way generators are written for Nx plugins.
See more about local generators
Reorganizing Projects
After some time of working within a workspace, projects might need to be moved or sometimes even removed.
The workspace plugin provides the @nx/workspace:move and @nx/workspace:remove generators to help aid with this.
Moving Projects
Running nx g @nx/workspace:move --projectName my-lib --destination new/location/my-lib will move the my-lib library to libs/new/location/my-lib.
Moving the files manually can be done easily but a lot of steps are often missed when projects are moved. This generator will also handle the following:
- The project's files will be moved
- The project will be renamed to
new-location-my-lib - The path mapping in
tsconfig.base.jsonwill be changed to@npmScope/new/location/my-lib - Imports in other projects will be changed to
@npmScope/new/location/my-lib - Paths in target options such as output path will be changed
- Other configuration will be updated too, such as
extendsintsconfig.json, the name of the project injest.config.js, and the extends in.eslintrc.json
See more about
@nx/workspace:move
Removing Projects
Running nx g @nx/workspace:remove my-lib will remove the my-lib from the workspace. It is important to note that sometimes, projects cannot be removed if they are still depended on by other projects.
Like when moving projects, some steps are often missed when removing projects. This generator will also handle the following:
- Checks if other projects depend on the project being removed. This can be ignored via the
--forceRemoveflag. - The project's files will be deleted.
- The project's configuration will be removed.
- The path mapping in
tsconfig.base.jsonwill be removed.
See more about
@nx/workspace:remove