【发布时间】:2021-11-24 04:09:00
【问题描述】:
当我从角度预设创建新的 nx 工作区时,我想插入 .editorconfig、.eslintrc.json 和 .prettierrc 的自定义(公司范围)配置,而不是每次都复制它们。
有没有办法自定义 create-nx-workspace?
作为后备,我会对覆盖上述文件的某种“ng add ...”(或正确的 nx 替代方案)感到满意。
【问题讨论】:
标签: angular nx.dev nx-workspace
当我从角度预设创建新的 nx 工作区时,我想插入 .editorconfig、.eslintrc.json 和 .prettierrc 的自定义(公司范围)配置,而不是每次都复制它们。
有没有办法自定义 create-nx-workspace?
作为后备,我会对覆盖上述文件的某种“ng add ...”(或正确的 nx 替代方案)感到满意。
【问题讨论】:
标签: angular nx.dev nx-workspace
我借此机会调查了Angular Schematics。
我有一个小的“ng-add”原理图,它会用我自己的文件覆盖文件并安装所需的依赖项。
由于这些都是根目录下的文件,所以原理图规则很简单(所有模板都在files文件夹中,就像建议的那样):
import {
Rule,
SchematicContext,
Tree,
apply,
url,
mergeWith,
template,
MergeStrategy,
} from "@angular-devkit/schematics";
export function ngAdd(options: any): Rule {
return (tree: Tree, context: SchematicContext) => {
const templateSource = apply(url("./files"), [template(options)]);
const merged = mergeWith(templateSource, MergeStrategy.Overwrite);
return merged(tree, context);
};
}
所以在我使用npx create-nx-workspace --preset=angular 创建工作区后,我可以只使用nx add my-schematics,它具有我需要的形状。
【讨论】: