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:-
Generate nestsjs module in libs
Create nestjs service for that module in libs folder
Any help is much appreciated.
I got the command that does the job finally and sharing with other encase they require help
ng generate #nestjs/schematics:library mynestlib
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"
},
I've came across the same problematic lately.
While #Atul Chaudhary can solve the issue in a different way,
I could solve my problem following this comment
So basically, you just have to add a new nest-cli.json file to your nx workspace root folder and specify these basic informations according to your project's structure.
nest-cli.json basic example
{
"collection": "#nestjs/schematics",
"sourceRoot": "apps/api/src"
}
Hope it can help some people :)
Nx now has direct support for NestJS via their #nrwl/nest plugin. They also have this tutorial that you may find useful.
Related
I created a yarn workspace alongside typescript as such.
I have three folders with their own package.json
/api
/client
/lib
The point is to share code from lib between API and client. In an API file for example I can do
import {User, UserAccount} from '#myproject/lib'
There are problems with this.
I need to build lib each time I change something
/api's build files point to C:/myproject/lib/build/index.js
Since I would like to deploy the project to heroku by just pushing what's in /api/build, this will fail because it can't find the files in /lib/build. Maybe I can push both build folders up to heroku, but what I was hoping for was some magic that compiled all /lib/src files into /api/build. My /client is running in expo which I assume uses something like webpack or I don't know what, and it seems to do this. Do I need to use webpack to acheive this or can I do it with yarn workspaces and typescript?
In tsconfig.json of client and api packages you need two configs, if you don't already have them:
In "compilerOptions" make sure you have "composite": true
Add "references": [{ "path": "relativePathTo/lib" }]
When you run tsc, run it with the --build (-b) flag, like this: tsc -b. This will build the active package and any package in references. More on TypeScript Project References.
This fixes your problem in development. Depending on your project configuration, you may need to do more things to put it through the CI.
I have created a common utility package which will be used by multiple node applications and for bundling it, I am using parcel which works fine but except one issue.
The common utility package consists of config files, which takes care of loading configuration as per env.
Issue:
While using this common utility package in a nodeapp I get the below error, when i try to run the app:
Error: loggerConfig config variable not found
at Object.n [as getLoggerConfig] (/Users/pm/Documents/example-service/node_modules/common.utils/dist/index.js:14:1037)
So It seems to me, the config files are not bundled along the build files generated.
Help Needed:
Is there a way we can tell parcel to bundle these config files as well?
Please guide me if I am thinking the wrong way.
Thanks in advance.
I've got quite some experience in (web) development (Java, ASP.NET and PHP amongst all), and fairly new to React and Node JS.
Although I did multiple tutorials and read multiple articles, I feel like I'm missing some point here and there. Currently I'm working on a React app which implements a nice HTML template I found.
One React tutorial I did used Webpack for building and deploying the app (local). This works nice, does the job of transpiling ES6 (.jsx) and SASS using babel. So far so good :)
My template has an image slider (Owl Carousel), so I installed the react-owl-carousel module.
This gave me quite some problems with jQuery (also installed as a module).
After several attempts to fix this I decided to move on to another slider module, React Awesome slider.
I used the module as the README.md explained. But upon building it (npm run build), I got an error that the .scss file within react-awesome-slider could not be transpiled. A message like "are you missing a loader".
So I installed sass, node-sass, sass-loader etc etc and configured these in my webpack.config.js.
I also noticed the react-awesome-slider module within node-modules contained a webpack.config.js.
Long story so far, sorry, now to the essence of this question.
In what way can the modules installed (like react-awesome-slider) be considered "black boxes"?
It doesn't feel logical that all the modules get build when building the main app. The "exclude: /node_modules/," config in webpack.config.js prevents this, not?
So why does the react-awesome-slider give an error about .scss transpiling? I had no .scss rule in my webpack config then.
Will all dependend modules automatically get installed when installing a new module? So when I run "npm i react-awesome-slider --save-dev", will its dependencies also be installed? Or is this not necessary? And do I need to update (webpack) configuration after installing a new module? Or is it really black box and "self-containing"?
Any help would greatly be appreciated!!! Maybe there is a good react-webpack sample app on Github or something like that?
That also confusing me for a really long time. Here are some answers to your question.
people publish packages to the NPM, so a module your project depends on
can be pre-builded or source code, it depends. I have checked react-awesome-slider, it's main field in package.json is dist/index.js, directly import it won't cause an issue because there are no SCSS files.If you follow the CSS module usage instruction you have import react-awesome-slider/src/styles and you will find src/styles.js file import ../styled.scss,so webpack will load it with SCSS loader which you have not configured, that's why an error occurred.
while you install modules, npm will go
through its dependency tree, install its dependencies, dependencies'
dependencies, until there's no more dependency module to install. before npm 3.0 the node_module folder is tree structure reflects the dependency tree, but it causes problems that many modules relay on the same dependency, npm will download and save too many same files, after version 3.0 it becomes flat(release note here, search flat keyword).
You don't need to update your webpack config after you install a dependency cause webpack build process will handle it with file dependency tree. You have installed a package and import it in your activation code, file there will be handle( with its package.json main field file as an entry), you have installed a package without using it or import it in a dead file(dead file means you cannot find it from webpack entry file), it will be ignored by webpack as it's dead code.
I have too many confuse until I read npm docs. Good luck to you.
Node modules are build to execute packages.When the are compiled they have proper configuration to handle extensions that are imported in it and when you import something like .scss in your main app then it does not know about that extension then your webpack need rules to include that extensions.
It does exclude node_modules as the are pre-converted pr pre build.
More over webpack is bit tough so developers create CRA Have look at it.
i am new to node and react so please forgive me if this does not sound correct.
I will try to explain this as simple as possible, but would like to know if this process can be automated somehow during a script/build process.
I create a component called 'button.js' in lib folder.
i added a script in the package.json file. the script is "build": "babel lib -d build",
I run npm run build which creates a build folder with my 'button' component built.
i export the component in an index.js file like so:
export { default as Button } from './build/components/Button'
I am wondering if the final 2 steps can be combined into a single step i.e. build the component then export it into the index.js file? If so, could you please point me in the right direction of how this can be done?
It sounds like you're trying to manually manage a "monorepos", whereby you have lots of individual packages that are utilised as node modules within other packages in your solution.
I'd suggest checking out Lerna (https://github.com/lerna/lerna) which takes away some of this pain. It allows you to include internal modules into your packages as if they were normal, published npm modules.
I suggest you google on webpack. It's how most people turn a bunch of js files into a bundle.js file. This is making your website faster too, as clients only need to load 1 file.
Webpack is a big subject so look for a "webpack babel react" guide.
I have developed a nodejs project as an umd library, with the purpose to use it in a another nodejs project. The library project builds fine and generates the index.js file and index.min.js file.
But when I tried installing the library project locally using npm install "asolute path". It brings all the things in the library project. And the size of my project I want to use the library project grew. Seems it is because of all the files in library project is getting copied.
Thanks for any help in advance.
Have you added an .npmignore file?
Also, you'll probably want to use npm link for local development.