Skip to content

As projects grow in size, you often need to split out a particular folder in that project into its own library. In order to do this properly, you need to:

  1. Generate a new library to set up all the config files
  2. Move the code from the existing folder into the new library
  3. Clean up paths that were broken when you moved the code

If you're not sure which code you want to split into a new library, this can be a tedious process to repeat multiple times.

Here is a technique to use during the exploration phase to help identify which code makes sense to separate into its own library.

  1. Identify the folders that might make sense to separate into their own library
  2. In each folder, create a project.json file with the following contents:
project.json
{
"name": "[name_of_the_folder]"
}

Now, run nx graph to view the dependencies between the folders. In the full web view (not in the graph below), you can click on the dependency lines to see which specific files are creating those dependencies.

Here is a graph that was created when doing this exercise on the Angular Jump Start repo. To reproduce this graph yourself, download the repo, run nx init and then add project.json files to the folders under /src/app.

Loading...
  1. Delete the empty project.json files.
  2. Make new libraries for any folders that were marked to be extracted into new libraries.