'Building Angular for production without installing devDependencies
I am currently trying to create a Docker container to build my production Angular app. I am using npm. I want to install dependencies only (so no devDependencies), so I want to do this:
npm install --only=prod
ng build project-name --prod
The only problem is that I am missing a lot of packages like @angular/cli and @angular-devkit/build-angular for my build. I couldn't find any good solutions on the internet, but I don't want my build to include all my devDependencies. Also, I don't want my production build to contain any of the packages required to build. Is there a good solution for this?
Solution 1:[1]
All the npm packages you use in development phase won't be included in your production build. It does not require any special command when installing your packages. You install all the packages you need or run npm install for an existing project as usual.
When deploying your Angular app with ng build prod it only includes critical packages to your app and dependencies you include in your angular.json file under the build section.
Try it yourself: take any angular project, run npm install or add npm packages then run ng build prod, navigate into the dist folder inside your project folder and look how there is less stuff compared to your project, especially inside node_modules folder.
Solution 2:[2]
This command will solve dependency problem :
ng build --configuration=production
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jim P. |
| Solution 2 | Elikill58 |
