Convert from a Standalone Repository to an Integrated Repository
In many ways, a standalone repository is an integrated repository, but with one primary app located at the root of the repository. Both types of repos use plugins to generate code and to keep dependencies and config files up to date. Both types of repos use executors to hide away unneeded complexity.
You can always add another app to a standalone repository the same way you would in an integrated repo. But at some point, you may want to move the primary app out of the root of your repo because the repo is no longer primarily focused on that one app. There are other apps that are equally important and you want the folder structure to align with the new reality.
Run the Generator
The convert-to-monorepo generator will attempt to convert a standalone repo to an integrated monorepo.
❯
nx g convert-to-monorepo
If you need to do the conversion manually, you can follow the steps below.
Manual Conversion Strategy
For this recipe, we'll assume that the root-level app is named my-app. The high-level process we'll go through to move the app involves four stages:
- Create a new app named tempunderapps/temp.
- Move source and config files from my-appintoapps/temp.
- Delete the files for my-app.
- Rename apps/temptoapps/my-app
Steps
- Update the - workspaceLayoutproperty in- nx.jsonto be:nx.json- 1{ 2 "workspaceLayout": { 3 "appsDir": "apps", 4 "libsDir": "libs" 5 } 6} 7- This will make sure that new apps are created under - appsand new libraries are created under- libs.
- If there is a - tsconfig.jsonfile in the root, rename it to- tsconfig.old.json- This step is to make sure that a - tsconfig.base.jsonfile is generated by the app generator in the next step.
- Create a new app using the appropriate plugin under - apps/temp- ❯ - nx g app temp 
- Move the - /src(and- /public, if present) folders to- apps/temp/, overwriting the folders already there.
- For each config file in - apps/temp, copy over the corresponding file from the root of the repo.- It can be difficult to know which files are root-level config files and which files are project-specific config files. Here is a non-exhaustive list of config files to help distinguish between the two. - Type of Config - Files - Root-level - .eslintignore,- .eslintrc.base.json,- .gitignore,- .prettierignore,- jest.config.ts,- jest.preset.js,- .prettierrc,- nx.json,- package.json,- tsconfig.base.json- Project-level - .eslintrc.json,- index.html,- project.json,- jest.config.app.ts,- tsconfig.app.json,- tsconfig.json,- tsconfig.spec.json,- vite.config.ts,- webpack.config.jsjest.config.app.ts- jest.config.app.tsin the root should be renamed to- jest.config.tswhen moved to- apps/temp. Also update the- jestConfigoption in- project.jsonto point to- jest.config.tsinstead of- jest.config.app.ts.
- Update the paths of the project-specific config files that were copied into - apps/temp.- Here is a non-exhaustive list of properties that will need to be updated to have the correct path: - Config File(s) - Properties to Check - project.json- $schema,- sourceRoot,- root,- outputPath,- reportsDirectory,- cypressConfig,- lintFilePatterns,- index,- main,- tsConfig,- assets,- styles,- jestConfig- tsconfig.json,- tsconfig.app.json,- tsconfig.spec.json- extends,- outDir,- files- .eslintrc.json- extends- jest.config.ts- preset,- coverageDirectory- vite.config.ts- cacheDir,- root,- dir
- Doublecheck that all the tasks defined in the - apps/temp/project.jsonfile still work.- ❯ - nx build temp - ❯ - nx test temp - ❯ - nx lint temp 
- Move the - /e2e/srcfolder to- /apps/temp-e2e, overwriting the folder already there
- For each config file in - apps/temp-e2e, copy over the corresponding file from the root of the repo. Update the paths for these files in the same way you did for the- my-appconfig files.
- Update the - /apps/temp-e2e/project.json- implicitDependenciesto be- tempinstead of- my-app
- Doublecheck that all the tasks defined in the - apps/temp-e2e/project.jsonfile still work.- ❯ - nx lint temp-e2e - ❯ - nx e2e temp-e2e 
- Delete all the project specific config files in the root and under - e2e
- Once the - project.jsonfile has been deleted in the root, rename- temp-e2eto- my-app-e2eand rename- tempto- my-app- ❯ - nx g move --projectName=temp-e2e --destination=my-app-e2e - ❯ - nx g move --projectName=temp --destination=my-app 
- Update the - defaultProjectin- nx.jsonif needed
- Check again that all the tasks still work and that the - nx graphdisplays what you expect.