How to create a new project in angular offline?
While creating a new project in Angular, it always needs an internet connection to download packages. This also takes much time here.
As I understand, the packages are pretty standard, so if one project is created; there should be provision to take it from repo created earlier.
Is there a way to create a project offline?
The command I use to create a new project is ng new <project name>
Solution 1:
Following steps can be used to create the ng project offline.
1- First create only the project structure skipping additional installtions
/> ng new ProjectName --skip-install (Use –skip-npm in older version. also you can use --skip-install=true )
2- Copy the node_modules folder from an existing project and paste inside your newly created project
3- Only pasting the dependencies is not sufficient. For the configurations to take effect run below command inside your project folder.
/> npm install
Please note that I had disabled the internet connection to check the dependencies were not downloaded from internet again (~284 MB).
4- You can see the message like "added 70 packages, removed 263 packages, updated 94 packages and moved 12 packages in 111.811s". You are done. Check the project is running in the browser after executing command:
/> ng serve
Update: Another way to re-use "ng_modules" like shared library
I found another way to reuse ng_modules. By creating a junction (symbolic link of existing ng_modules inside the new project, we don't have to copy paste this folder.). But this approach has its own disadvantage as its always good to keep all stuff related to one project at one place. So use this for small dev/testing projects only.
Solution 2:
If you are using the angular CLI you can use --skip-install
flag so you can skip installing all the NPM packages.
So basically, you can create a new project using the following command:
ng new yourProject --skip-install