Difference betwen npm run build, ng build and ionic build

Hey guys, noob here. I have watch tutorials on ionic and angular, and I just can’t differentiate all these 3 as saw different developers used 3 different kinds of command.

  • npm run build
  • ng build
  • ionic build

Can anyone tell me what’s the difference and which one should I actually run for my ionic project?

Possibly answered here https://stackoverflow.com/questions/61837135/difference-betwen-ng-build-and-ionic-build/64872246#64872246

As far as I know-

  1. ionic build uses ng build internally.
  2. If you run ng build directly, Ionic hooks won’t be triggered as it is bypassed.
  3. npm run build picks the "build" from package.json which is the same as ng build. It is helpful for CI where you do not have ionic or ng commands available. There you can simply run npm run build -- --prod.

To build on @sagrawal’s answer, you can change what npm build does by editing package.json, so while it may be true that by default it’s "the same as ng build", it certainly doesn’t have to be. I’m also not clear on why one can’t have ionic or ng CLI tools in a CI build - I have done this before.