At what stage should I run my 'npm run build' script?

I’m trying to figure out at what stage I should run my npm run build script that creates dist folder, I was thinking somewhere during my deployment so

  # Staging
    branch: staging
    commands: - npm run build
      ... etc

But I can’t find any confirmation of this, hence asking here

If anyone has an answer to this, I’d like to find out too!

I ran into an error when trying to run npm run build --prefix ./