Angular provides already a ng build command as well as an option for production environment. But how can this be transfered to your existing continuous delivery infrastructure. Imaging you have got a Bamboo or Jenkins responsible for building and deploying your software application.
You cannot simply add ng build –prod for building the application, since ng won’t be found by the executing agent. ng is in the angular guides always installed globally with npm install -g @angular/cli. This should not be done on your CD-Server, since you won’t want globally use the same angular-cli if you have multiple application. It would be a huge administrative overhead to always keep all the applications on the same versions.
I prefer to add a script to the package.json in (scripts-Array) for building the artifact on the CD-Server.
"artifactBuild": "node ./node_modules/@angular/cli/bin/ng build --prod"
Thus we are using the pinned angular cli version of the project. In the build plan you add following commands:
yarn install --no-bin-links yarn run artifactBuild
Or for npm
npm install --no-bin-links npm run-script artifactBuild