首页 > 解决方案 > 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 之后再次发生。就在几天前一切正常!

标签: angular

解决方案


你可能已经通过这个命令安装了@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


推荐阅读