且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Angular 2+ 中生成没有 spec.ts 文件的组件

更新时间:2022-12-07 18:58:14

针对 Angular >=8 CLI 进行了更新

对于一个组件,使用以下命令:

For one component use the following command:

ng generate component --skip-tests=true component-name

对于单个项目,在您的 angular.json 中更改或添加以下内容:

For a single project, change or add the following in your angular.json:

{ 
  "projects": {
    "{PROJECT_NAME}": {
      "schematics": {
        "@schematics/angular:component": {
          "skipTests": true
        }
      }
    }
  }
}

对于所有项目的全局设置,请在 angular.json 中更改或添加以下内容:

For a global setting for all your projects, change or add the following in your angular.json:

{ 
  "schematics": {
    "@schematics/angular:component": {
      "skipTests": true
    }
  }
}

或者使用命令行

ng config schematics.@schematics/angular:component.skipTests true


在您的 angular-cli.json 中,将 spec.component 参数设置为 false:

Inside your angular-cli.json set the spec.component parameter to false:

{
   ...
   "defaults" : {
       ...
       "spec": {
           ...
           "component": false
       }
   }
}

或在创建过程中使用 --spec=false 选项

or use the --spec=false option during creation

ng generate component --spec=false component-name