简体   繁体   English

NX Angular 多个同名库

[英]NX Angular multiple libs with the same name

So I am using Angular with NX and I have the following groups books and cars .所以我在 NX 中使用 Angular,我有以下组bookscars For both groups I want to create an overview lib with a table to view the books or cars.对于这两个组,我想创建一个带有表格的overview库来查看书籍或汽车。

So I create the lib under libs/books/overview next up I want to do the same for cars libs/cars/overview .所以我接下来在libs/books/overview下创建了 lib 我想对汽车libs/cars/overview做同样的事情。 But then I run into this issue:但后来我遇到了这个问题:

Error: Project name already exists.

Do I need to name the libs like books-overview ?我需要将库命名为books-overview吗? Then I would create the following lib: libs/books/books-overview .然后我将创建以下库: libs/books/books-overview books is redundant so it doesn't seem like the best option. books是多余的,所以它似乎不是最好的选择。

I think the best option here is create a folder overviews with the libs inside.我认为这里最好的选择是创建一个包含库的文件夹overviews For instance:例如:

libs/overviews/cars

libs/overviews/books

The folder name does not have to be same as the app.文件夹名称不必与应用程序名称相同。 Instead, you could create parent folder for each dash separated part of your library name.相反,您可以为库名称的每个破折号分隔部分创建父文件夹。

You can create lib with name 'books-overview' in folder books/overview .您可以在文件夹books/overview创建名为'books-overview'


Running the command with the folder structure as name, it correctly decides on the name.以文件夹结构作为名称运行命令,它正确地决定了名称。 Running跑步

npx ng generate @nrwl/workspace:library --name=books/overview

will generate library 'books-overview' in folder books/overview .将在文件夹books/overview生成图书馆'books-overview'


For example this is config of our application (we also use nx):例如,这是我们应用程序的配置(我们也使用 nx):

// angular.json excerpt
"api-java-model": {
  "projectType": "library",
  "root": "libs/api/java/model",
...
},
"api-java-client": {
  "projectType": "library",
  "root": "libs/api/java/client",
...

That way you don't have a folder collision.这样你就不会发生文件夹冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM