【问题标题】:How to create component in libs via angular schematics webstorm如何通过角度示意图 webstorm 在库中创建组件
【发布时间】:2021-04-01 11:15:31
【问题描述】:

我确实在 nx monorepo 中创建了一个 Angular 项目。当我创建 UI 库时,我想使用“Angular Schematic...”(看图片)

但是当我使用“原理图/组件”时,文件仍在我的应用程序上生成。

apps/project/src/app/test-component/..

我通过npx create-nx-workspace@latest 生成工作区并安装了@nrwl/schematics,但仍然无法正常工作。

另外,我确实向我的 angular.json 提供了这段代码:

  "schematics": {
    "@nrwl/schematics:component": {
      "styleext": "scss"
    },
    "@nrwl/schematics:library": {
      "prefix": "test",
      "unitTestRunner": "jest",
      "framework": "angular",
      "style": "scss"
    },
    "@nrwl/schematics:application": {
      "unitTestRunner": "jest",
      "e2eTestRunner": "protractor"
    },
    "@schematics/angular:component": {
      "styleext": "scss",
      "spec": true
    },
    "@schematics/angular:directive": {
      "prefix": "mor"
    },
    "@nrwl/angular:component": {
      "style": "scss"
    }
  },
  "cli": {
    "defaultCollection": "@nrwl/schematics",
    "analytics": false
  }

我忘记了一些配置吗?在 webstorm 中使用角度示意图需要做什么。

Angular CLI: 11.0.5
Node: 12.18.3
OS: win32 x64

Angular: 11.0.5
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: <error>

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.5
@angular-devkit/build-angular   0.1100.5
@angular-devkit/core            11.0.5
@angular-devkit/schematics      11.0.5
@schematics/angular             11.0.5
@schematics/update              0.1100.5
rxjs                            6.5.5
typescript                      4.0.5

【问题讨论】:

    标签: angular webstorm monorepo nrwl-nx


    【解决方案1】:

    在终端的库目录中运行ng g @schematics/angular:component 时,您将面临同样的问题;要获取在非默认项目中创建的组件,请尝试将--project 选项传递给ng g

    【讨论】:

    • 但是我在不同的项目中看到了我所描述的方式。不传递任何参数。 Webstorm 自动找到了你要创建组件的模块
    • 这不是关于 WebStorm,而是关于在 nx 工作区中使用 ng g。不知道为什么它在另一个项目中对你有用,我尝试过的是一个非常基本的 nx 工作区
    【解决方案2】:

    这个问题可能在 nx/nrwl 中。因为现在我安装了 nx version@11.2.10 和带角度的工作区。然后安装@nrwl/schematics(8.12.11) 一切正常。

    【讨论】:

      猜你喜欢
      • 2020-01-27
      • 2023-02-21
      • 2018-06-27
      • 2018-08-04
      • 2018-02-08
      • 1970-01-01
      • 2019-05-17
      • 2020-08-19
      • 2019-11-02
      相关资源
      最近更新 更多