nrwl / nx示意图创建角度应用程序并配置角度json

时间:2020-05-06 12:52:20

标签: angular nrwl nrwl-nx angular-schematics

我正在使用nrwl / nx monorepo。我的应用程序在angular.json中具有自定义配置。例如,输出路径是自定义的。现在,我想编写自己的原理图,它将配置我的项目。

我的问题是,我不知道如何编写示意图来更改angular.json中的属性。 我需要帮助。

最良好的祝愿。

1 个答案:

答案 0 :(得分:0)

这是一个通过nx-workspace示意图更改angular json中输出路径的选项:

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));
  }
}