【问题标题】:Use AngularCLI to generate components when there are multiple apps in your project当您的项目中有多个应用程序时,使用 AngularCLI 生成组件
【发布时间】:2018-02-13 04:59:55
【问题描述】:

我的 .angular-cli.json 文件如下所示:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "suman-chrome-extension"
  },
  "apps": [

    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
    },
    {
      "root":"blank-page-src",
      "outDir": "blank-page-dist",
      "index": "page.html",
      "main": "page.ts",
      "polyfills": "polyfills.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "blank-page",
    },

    {
      "root":"dev-tools-src",
      "outDir": "dev-tools-dist",
      "index": "suman-dev-tools.html",
      "main": "suman-dev-tools.ts",
      "polyfills": "polyfills.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "suman-dev-tools",
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {
    }
  }
}

我遇到的问题是,当我使用这样的命令时:

ng g service services/foo

它会将此服务放在第一个应用程序中。即使我 cd 进入子目录也会发生这种情况。

如何在除主/第一个应用之外的应用中生成组件/服务等?

【问题讨论】:

    标签: angular angular-cli angular5


    【解决方案1】:

    你应该给他们每个人一个像下面这样的名字

    .angular-cli.json

    apps: [
        {
            ...
            "name": "app-1"
            ...
        },
        {
            ...
            "name": "app-2"
            ...
        }
    ]
    

    然后,您可以创建组件/服务/管道/模块,如下所示

    ng g c my-component --app=app-1

    或者如果你不想命名它们(你应该这样做),你可以使用 index 以及如下

    ng g c my-component --app=0 --> 在第一个应用中创建一个组件

    ng g c my-component --app=1 --> 在第二个应用中创建一个组件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-23
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      相关资源
      最近更新 更多