对于 Angular 9 >(版本 6 > 以下)
1) 将 sn-p 复制到 angular.json 的根目录,(将设置配置到所有项目/全局)。
2) 或者将 sn-p 复制到根目录angular.json 中的特定项目 (projects.your-project-name)(配置特定项目的设置)。
"schematics": {
"@schematics/angular:component": {
"style": "scss",
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
},
"@schematics/angular:directive": {
"skipTests": true
},
"@schematics/angular:pipe": {
"skipTests": true
},
"@schematics/angular:service": {
"skipTests": true
}
},
每种文件类型的所有可配置选项Schematic Options:
"schematics": {
"@schematics/angular:component": {
"changeDetection": "Default",
"entryComponent": false,
"export": false,
"flat": false,
"inlineStyle": false,
"inlineTemplate": false,
"module": "",
"prefix": "",
"selector": "",
"skipImport": false,
"spec": true,
"style": "css",
"viewEncapsulation": "Emulated",
"skipTests": "false"
},
"@schematics/angular:module": {
"commonModule": true,
"flat": false,
"module": "",
"routing": false,
"routingScope": "Child"
},
"@schematics/angular:service": {
"flat": true,
"skipTests": true
},
"@schematics/angular:pipe": {
"export": false,
"flat": true,
"module": "",
"skipImport": false,
"skipTests": true
},
"@schematics/angular:directive": {
"export": false,
"flat": true,
"module": "",
"prefix": "app",
"selector": "",
"skipImport": false,
"skipTests": true
},
"@schematics/angular:class": {
"skipTests": true
}
},
对于 Angular 6 >
1) 将 sn-p 复制到 angular.json 的根目录,(将设置配置到所有项目/全局)。
2) 或者将 sn-p 复制到根目录angular.json 中的特定项目 (projects.your-project-name)(配置特定项目的设置)。
"schematics": {
"@schematics/angular:component": {
"styleext": "scss",
"spec": false
},
"@schematics/angular:class": {
"spec": false
},
"@schematics/angular:directive": {
"spec": false
},
"@schematics/angular:guard": {
"spec": false
},
"@schematics/angular:module": {
"spec": false
},
"@schematics/angular:pipe": {
"spec": false
},
"@schematics/angular:service": {
"spec": false
}
},
每种文件类型的所有可配置选项 (Schematic Options):
"schematics": {
"@schematics/angular:component": {
"changeDetection": "Default",
"export": false,
"flat": false,
"inlineStyle": false,
"inlineTemplate": false,
"module": "",
"prefix": "",
"selector": "",
"skipImport": false,
"spec": true,
"styleext": "css",
"viewEncapsulation": "Emulated"
},
"@schematics/angular:module": {
"commonModule": true,
"flat": false,
"module": "",
"routing": false,
"routingScope": "Child",
"spec": true
},
"@schematics/angular:service": {
"flat": true,
"spec": true
},
"@schematics/angular:pipe": {
"export": false,
"flat": true,
"module": "",
"skipImport": false,
"spec": true
},
"@schematics/angular:directive": {
"export": false,
"flat": true,
"module": "",
"prefix": "app",
"selector": "",
"skipImport": false,
"spec": true
},
"@schematics/angular:class": {
"spec": true
}
},
使用 Angular CLI 配置 Angular CLI
错误:
ng set defaults.spec.component false 命令导致错误:get/set have been deprecated in favor of the config command.
ng set 已更改为 ng config。
使用 Angular CLI(配置命令用法):
angular.json 中用于生成规范、内联模板、内联样式等的设置现在保留在 schematics.@schematics/angular.<file-type>.<setting> 内。
运行ng config schematics.@schematics/angular.component.spec false 为组件配置规范。此命令将设置添加到 angular.json 文件中的原理图属性内。
Angular CLI workspace file (angular.json) on Angular Github
Schematic options inside schema.json
How to do X in Angular CLI v6