Nx: NestJS: Support creating libs.

Created on 17 Jan 2019  路  10Comments  路  Source: nrwl/nx

  • [x] I am running the latest version
  • [x] I checked the documentation and found no answer
  • [x] I checked to make sure that this issue has not already been filed
  • [x] I'm reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)

Expected Behavior

Is there a way to use the create lib feature that works with angular but for NestJS. This would be really cool so we could separate the modules into libs. I could do this manually but i believe there are some additions to add to the angular.json etc

I am really loving where it is heading but having additional nestjs support and integration would be really nice.

Currently the nestjs create node-app doesn't really anything extra to what we can do manually but additions of the libraries would really bring some great functionality.

node feature

Most helpful comment

With regards to the angular.json section above. There are things like "prefix" and "stylext" that dont make a lot of sense now :-) ALthough, I was afraid to remove them and break something that is currently working :-) AHA HA

All 10 comments

If you create a nest library it will be created in libs. But if you lint it you will get the error:
All files in 'apps' and 'libs' must be part of a project.: The 'libs/test/package.json' file doesn't belong to any project.

So i added that manually. This works but the linter will complain with an error that does not tell me whats wrong.

So if libs is for angular libraries, I am really interested how one would work in a similar fashion with nest. So in terms of folder and project architecture.

I added a sample how I added them here: https://github.com/creadicted/nx-modular-nest-backend

Hi @creadicted , thanks for your input. Yes I also tried it.. I created my library, but the file is missing in angular.json so it complains about nx and angular.json being out of sync.

So I had to add a section for the library, what I did was create an angular library in a temp project and copy the structure into mine.

It would be nice if this was integrated into NX / Angular Console directly - as I am not sure 100% if I am doing it correctly :-)

@appsolutegeek - How did you managed that webpack rebuild is also triggered when you change something in a libray?

I agree, would love to see a library generator for nestjs in NX!

@creadicted I added the values to NX.json and angular.json

After run a

npm run lint

Which will lint your nx and angular to see if there is anything wrong. (it run nx lintas part of the linting process)

Here is an example of what is in the angular.json

    "shared-auth": {
      "root": "libs/shared/auth",
      "sourceRoot": "libs/shared/auth/src",
      "projectType": "library",
      "prefix": "xyz",
      "architect": {
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["libs/shared/auth/tsconfig.lib.json", "libs/shared/auth/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        },
        "test": {
          "builder": "@nrwl/builders:jest",
          "options": {
            "jestConfig": "libs/shared/auth/jest.config.js",
            "tsConfig": "libs/shared/auth/tsconfig.spec.json"
          }
        }
      },
      "schematics": {
        "@nrwl/schematics:component": {
          "styleext": "scss"
        }
      }
    },

and nx.json

    "shared-auth": {
      "tags": []
    },

The section in angular.json, I sort of figured it out. I dont know if its correct :-) but it does work. There is no build section but its part of the library.

Everytime i create a new library I must add things manually to the angular.json and nx.json and I have a sort of template directory of what a library should consist of i.e. tsconfig.spec.json, tsconfig.lib.json etc.. I sort of crafted these from creating a angular library and creating a nest library ... :-) . So, again, it may not be right but it works.

It would be so much better if we could do it with the NG CLI or via Angular Console.

Less error prone and cleaner :-)

With regards to the angular.json section above. There are things like "prefix" and "stylext" that dont make a lot of sense now :-) ALthough, I was afraid to remove them and break something that is currently working :-) AHA HA

So with the new --framework=none it is much easier to define a nestjs backed library.

ng generate @nrwl/schematics:library --framework=none

@creadicted , your command does not work (any more). Is it possible, that the --framework=none got removed?
I previously used

ng g @nrwl/workspace:lib NAME

to create a "normal" ts library..

Yes since the introduction of the workspace the general schematics:library was replaced

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SWGeekPD picture SWGeekPD  路  3Comments

markphip picture markphip  路  3Comments

jasedwards picture jasedwards  路  3Comments

elliotmendiola picture elliotmendiola  路  3Comments

Svancara picture Svancara  路  3Comments