6

I have an existing NX project name myorg. which have already three application name one, two, three. I am able to create a new application (name: four) into that NX project (myorg) by the command:

ng g @nrwl/schematics:application four

but I want to add an existing angular project (name: 'todos') into the existing NX project (name: myorg). What is the process ?

Note: I am able to add NX to an existing angular project by command:

ng add @nrwl/schematics

1 Answer 1

0

As of version 19.8, the Nx CLI has an import command that can be used to add an existing project to a monorepo. It should automatically update the configuration required to integrate the project into the monorepo, such as replacing the angular.json file with a project.json file, and merging the dependencies in the package.json file.

The command can be used as follows:

nx import [sourceRepository] [destinationDirectory]

The sourceRepository parameter can be a URL to a repository or another directory, and the destinationDirectory parameter should be the project's new path within the monorepo. For example:

nx import https://github.com/example/todo.git apps/todo

More info is available in the Nx documentation.


For prior versions of Nx, the process is a bit more complicated but the general idea is as follows, presuming you are using Git:

  • Before starting, make sure there are no dependency conflicts between projects and the both the source and the monorepo are using the same versions of Angular as well as other dependencies they may share.
  • Create a new Git branch in the source project. On that branch, move all the files into a subdirectory that matches the path the app will have once it is merge into the monorepo, such as apps/todo.
  • In the monorepo, add the source project as a new Git remote. You can then merge the branch with the code in a subdirectory, into the monorepo. (How to import a Git repo into another.)
  • With the code merged into the monorepo, you then need to adapt the configuration. Rename angular.json to project.json, merge the dependencies for the source project into the monorepos packages.json and update the ESLint and TS config files to inherit the base config for the monorepo. You can compare the config with the config for your other apps or generate a new app to use as a reference to ensure everything is set up correctly.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.