0

I'm working in a nrwl/nx monorepo. My applications are having a custom configuration in angular.json. For example the output path were customized. Now i want to write my own schematic, which will configure my project.

My problem is, I don't know how to write a schematic which can change properties in angular.json. I need help.

Best wishes.

Lukas
  • 155
  • 1
  • 2
  • 7

1 Answers1

0

This in one option to change the output path in angular json via nx-workspace schematic:

function updateOutputPath(name: string, prefix: string): Rule {
  return (host: Tree) => {
    const angularJson = JSON.parse(host.read('angular.json').toString());
    const appOutputPath = angularJson.projects[name].architect.build;
    const appPrefix = angularJson.projects[name];
    appPrefix.prefix = `${name}`;
    appOutputPath.options.outputPath = `dist/${prefix}/static`;
    angularJson.projects[name] = prefix;
    angularJson.projects[name].architect.build = appOutputPath;
    host.overwrite('angular.json', JSON.stringify(angularJson));
  }
}
Lukas
  • 155
  • 1
  • 2
  • 7