Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To relocate the node_modules directory from within the Angular project, you can follow these steps:

  1. Open the angular.json file in the root directory of your project.
  2. Locate the "build" configuration for your project.
  3. Add a new "options" property to the "build" configuration.
  4. Within the "options" property, add a "outputPath" property with the new location for the node_modules directory.
  5. Save and close the angular.json file.

Here is an example of what your "build" configuration should look like:

"build": {
  "builder": "@angular-devkit/build-angular:browser",
  "options": {
    "outputPath": "../node_modules/my-project"
  },
  "configurations": {
    "production": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.prod.ts"
        }
      ],
      "optimization": true,
      "outputHashing": "all",
      "sourceMap": false,
      "extractCss": true,
      "namedChunks": false,
      "aot": true,
      "extractLicenses": true,
      "vendorChunk": false,
      "buildOptimizer": true
    }
  }
}

In this example, the nodemodules directory will be relocated to the ../nodemodules/my-project directory, which is one level above the root directory of the Angular project. You can replace this path with any directory path that you prefer.