Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nrwl nx command to generate lib for nest module

I am new to nrwl nx cli and extensively searched through their documentation and could not find the command to generate the nestjs module as lib rather than the actual module within app.

The reason why I want to create the nestjs module as lib is becuase I have got several nestjs applications in my mono repo and as per nrwl nx guidelines if I have to share code, which is module in my case, it has to be a lib.

Can anyone please share the command to do the following thing:-

  1. Generate nestsjs module in libs
  2. Create nestjs service for that module in libs folder

Any help is much appreciated.

like image 956
Atul Chaudhary Avatar asked Mar 28 '19 12:03

Atul Chaudhary


People also ask

What is NRWL workspace?

The workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.


Video Answer


2 Answers

I got the command that does the job finally and sharing with other encase they require help

ng generate @nestjs/schematics:library mynestlib
like image 146
Atul Chaudhary Avatar answered Nov 03 '22 02:11

Atul Chaudhary


Quote from Nx Workspace official documentation :

Creating a Lib Adding new libs to an Nx Workspace is done by using the Angular CLI generate command, just like adding a new app.

ng generate lib mylib
ng generate library mylib # same thing

This will create a new lib, will place it in the libs directory, and will configure the angular.json and nx.json files to support the new lib.

Run ng generate lib --help to see the list of available options.

ng generate lib mylib --directory=myteam will create a new application in libs/myteam/mylib.

If --directory is not defined, it will ask you in which directory it should be generated, and what framework should be used (Angular or TS).

If it's not working, please, maybe you should check your Nx version, and also your angular.json.

@nrwl/schematics could not be the default collection used as this issue mentioned.

angular.json

"cli": {
  "defaultCollection": "@nrwl/schematics",
  "packageManager": "yarn"
},
like image 27
Thierry Falvo Avatar answered Nov 03 '22 01:11

Thierry Falvo