skip to Main Content

I want to execute pocketbase.sh shell command at SvelteKit application which uses Vite, on startup. Do you have any ideas how do I achieve this?

enter image description here

2

Answers


  1. Perhaps the best way to do this is within your package.json. In there you will see (among others) the dev script with something like vite dev. In order to run this script on startup, just ensure it runs before the original command. For example, something like this:

    sh ./pocketbase/pocketbase.sh && vite dev
    

    This will get you covered for the dev environment. As per the prod environment (if needed), you will need to figure it out what command you need and do the same. For example, as I use the node adapter, the command I use to run the project is node build/index.js so, if this was also yours, you could add the prod command into your package.json like this:

    sh ./pocketbase/pocketbase.sh && node build/index.js
    

    And then you could run it with npm run prod.

    Other options would be to execute a command from javascript itself but I think running it from package.json is far better and simpler.

    Login or Signup to reply.
  2. I’m using concurrently

    pnpm/npm -D install concurrently

    {
        "scripts": {
            "dev": "concurrently "vite dev --host" "cd backend && go run main.go serve --http=127.0.0.1:8080"",
            "site": "vite dev --host",
        }
    }
    

    Instead of my command cd backend && go run main.go serve --http=127.0.0.1:8080 replace it with yours, because i’m using pocketbase as a framework

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search