我目前正在尝试创建我自己的自定义 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/