当我使用“ ng generate”命令时,它将使用引号将路径写成我的导入语句。我希望它改为使用单引号。是否可以通过某种方式进行配置?
Voj*_*cka 18
您目前(从 7.1 开始)无法配置 Angular 以生成带有您选择的引号的组件和其他实体。它目前使用单引号。如果您对此不满意,您可以告诉它自动运行 tslint 并在生成后自动修复所有问题。
首先,确保您有在您的tslint.json: 中强制执行双引号的规则:
"quotemark": [true, "double"],
Run Code Online (Sandbox Code Playgroud)
接下来,在angular.json原理图部分(在根级别)中,您可以提供选项lintFix告诉 angular 根据您的 tslint 配置自动修复生成的文件:
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "scss",
"lintFix": true
},
"@schematics/angular:directive": {
"prefix": "app",
"lintFix": true
},
"@schematics/angular:pipe": {
"lintFix": true
},
"@schematics/angular:class": {
"lintFix": true
},
"@schematics/angular:module": {
"lintFix": true
},
"@schematics/angular:service": {
"lintFix": true
}
}
Run Code Online (Sandbox Code Playgroud)
这应该在 linux 上运行良好,但在 Windows 上,当前存在bug,它在生成时使用了错误的文件路径。在它被修复之前,你不能直接在你的components目录中生成组件,而是需要在项目根目录中生成它并在命令路径中指定它应该生成的目录:
ng g component components/my-component my-component
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2061 次 |
| 最近记录: |