Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

georgetown74's avatar

Adding npm run build process to deploy script with Laravel Forge?

I completed the "Build A Voting App" Laracast series, made very minor modifications to customize it for my use case, and deployed it into a production environment using Laravel Forge. I notice the site looks different in production than it does locally, and I fix it locally by running "npm run dev" in Terminal. I tried running "npm run build" using the "Commands" feature of Forge and then I refresh my browser but nothing changes. Do I need to add "npm run build" or something similar to the actual deployment script in Forge or is there another solution? Thanks in advance!

0 likes
6 replies
MohamedTammam's avatar

Two options

  1. Adding npm run prod to your build script
  2. remove your build files from .gitignore

If you already deployed and you want to fix that, you can run npm run prod from the commands page on Forge.

georgetown74's avatar

@MohamedTammam Thank you for the response! I think my AWS instance size may have been too small, so I stopped it, resized it, and when I loaded the site again the site looks as expected. At this point the build files are still being ignored but it seems I didn't have to explicitly run "npm run prod" either. I assume the build process needed more resources to work correctly but I am not sure why it's working now without me actively running a command.

MohamedTammam's avatar

@georgetown74 You mentioned that you've ran npm run build already.

It is the same as npm run prod but doesn't minimize the files and doesn't remove dev features from build files.

georgetown74's avatar

@MohamedTammam OK, the Forge dashboard showed that it timed out. (I know it does that for anything that takes longer than 2 minutes but I wasn't sure it had actually finished all the way through). So back to your original suggestion about adding npm run prod to my build script... Can you please clarify the steps involved? I think the first step is to update my package.json file from this:

    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },

... to this:

    "scripts": {
        "dev": "vite",
        "prod": "vite",
        "build": "vite build"
    },

... and then update my deploy script in Forge by adding a line like this:

$FORGE_COMPOSER npm run prod

Sorry if these questions are basic!

MohamedTammam's avatar
Level 51

@georgetown74 I'm sorry, I'm really sorry. I was speaking about Laravel Mix commands not Laravel vite.

You were running the right command npm run dev, with vite forget about what I said about npm run prod.

georgetown74's avatar

@MohamedTammam No worries, thanks for clarifying that. I will look into adding that to my Forge deploy script. Thanks for all your help!

1 like

Please or to participate in this conversation.