angular - angular cli ng generate 组件忽略了 angular.json 的默认值
问题描述
似乎又是一个老问题了。可悲的是:
Angular CLI: 7.3.7
Node: 10.14.1
OS: win32 x64
Angular: 7.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.13.7
@angular-devkit/build-angular 0.13.7
@angular-devkit/build-optimizer 0.13.7
@angular-devkit/build-webpack 0.13.7
@angular-devkit/core 7.3.7
@angular-devkit/schematics 7.3.7
@angular/cdk 7.3.6
@angular/cli 7.3.7
...
ng generate 组件仍然忽略 angular.json 上的默认设置:
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "ids",
"schematics": {
"@schematics/angular:component": {
"inlineStyle": false,
"inlineTemplate": false,
"spec": false,
"styleext": "scss"
}
},
所以我需要在每一代组件上设置所有选项。我唯一的线索是它在 npm install @ngx/schematics 之后再次发生。就在几天前一切正常!
解决方案
你可能已经通过这个命令安装了@ngrx/schematics :
ng add @ngrx/schematics --defaultCollection
此命令将使用您首选的数据包管理器安装@ngrx/ schemics,更新您的package.json并通过添加以下内容更新您的angular.json文件:
"cli": {
"defaultCollection": "@ngrx/schematics"
}
这将扩展 Angular 的标准原理图并添加添加 NgRx 特定文件的功能ng generate
(如动作、效果等......)。如果您之前对 Angular 项目配置进行了更改(例如使用 scss),您应该更新您的原理图条目。
你只需要改变
"schematics": {
"@schematics/angular:component": {
"inlineStyle": false,
"inlineTemplate": false,
"spec": false,
"styleext": "scss"
}
},
至
"schematics": {
"@ngrx/schematics:component": {
"inlineStyle": false,
"inlineTemplate": false,
"spec": false,
"styleext": "scss"
}
},
您将在以下 GitHub 问题中获得更多信息:https ://github.com/ngrx/platform/issues/1036
推荐阅读
- python-3.x - 将操作应用于 numpy 数组中的特定列
- jackson - 字符串的杰克逊反序列化为 LocalDateTime 不一致
- javascript - 如何使用 t-jquery 和 t-operation 扩展模板属性(Odoo 14)
- google-bigquery - Concatenate strings in BigQuery
- sql - Netsuite 保存的搜索中的 TRIM 或 REPLACE
- webpack - 当我在观看模式下保存文件时,Storybook webpack 构建冻结在 70%
- python - 我可以在 Dash 中缩小旭日形图与其色标之间的间距吗?
- javascript - 无法使用 requests_html 抓取网站
- azure-sql-database - AzureSQL PaaS不同数据库表的DML操作
- python - 过滤元组列表以从包含的另一个元组列表中排除