首页 > 解决方案 > Angular6:如何从命令行生成默认的 angular.json 文件

问题描述

我使用 Angular 6 创建了一个新模块,它将作为一个包在另一个项目中使用。

现在,我正在尝试配置 karma 和 jasmine,以便可以在其上创建单元测试。问题是我发现该项目没有任何angular.json文件。

angular.json可以从命令行生成默认文件吗?

标签: angularunit-testingkarma-jasminekarma-runnerangular-cli-v6

解决方案


最好的办法是按照 danday74 的建议生成一个新项目,然后从该生成的项目中复制 angular.json 文件:

ng new project-name

快速检查“ng”命令行选项不会显示任何用于独立生成新 angular.json 的选项:

 ng -h
Available Commands:
  add Add support for a library to your project.
  new Creates a new directory and a new Angular app.
  generate Generates and/or modifies files based on a schematic.
  update Updates your application and its dependencies.
  build Builds your app and places it into the output path (dist/ by default).
  serve Builds and serves your app, rebuilding on file changes.
  test Run unit tests in existing project.
  e2e Run e2e tests in existing project.
  lint Lints code in existing project.
  xi18n Extracts i18n messages from source code.
  run Runs Architect targets.
  eject Temporarily disabled. Ejects your app and output the proper webpack configuration and scripts.
  config Get/set configuration values.
  help Help.
  version Outputs Angular CLI version.
  doc Opens the official Angular API documentation for a given keyword.

您还可以根据Github 上 Angular CLI 项目提供的文档手动创建自己的 angular.json 。


推荐阅读