gpt4 book ai didi

angular - 如何在自定义 Angular Schematics 中定位文件路径?

转载 作者:行者123 更新时间:2023-12-02 20:21:43 27 4
gpt4 key购买 nike

我目前正在尝试创建我自己的自定义 Angular Schematics。我有以下内容:

import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';


// You don't have to export the function as default. You can also have more than one rule factory
// per file.
export function pxSchematics(options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
tree.create(options.name || 'hello', 'world');
return tree;
};
}

这只是创建一个包含“hello world”的文件。我将如何更改树的文件路径,以便它在自定义目录中输出文件?谢谢。

最佳答案

您可以只指定所需的路径:

import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { normalize } from "@angular-devkit/core";

export function pxSchematics(options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
tree.create(options.name || normalize('sorts/hello'), 'world');
return tree;
};
}

关于angular - 如何在自定义 Angular Schematics 中定位文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51217262/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com