2

Is there a way to run terminal commands simultaneously

Like php artisan serve

And npm run dev (for laravel vite)

Run it in a comment or terminal with a shortcut

dante velli
  • 369
  • 1
  • 13
  • 1
    You can define a composer script that do both : `"serve": ["npm run dev", "php artisan serve"]` and then `composer serve` it will run both commands one after another. You can also use npm scripts instead, it's the same thing, like `npm run serve`, the only difference is that it's a string not an array ; `"serve": "npm run dev && php artisan serve"` – Lk77 Oct 04 '22 at 06:56
  • Does this answer your question? [How can I run multiple npm scripts in parallel?](https://stackoverflow.com/questions/30950032/how-can-i-run-multiple-npm-scripts-in-parallel) – Matt Oct 04 '22 at 09:05
  • 1
    @Lk77 unless the first is a long running process, then the second won't run until the first exits cleanly. – Matt Oct 04 '22 at 09:07
  • @Matt that's intended, because we need to wait for build to finish before serving, if we do the other way around, we will have an error on laravel side stating that build files are missing – Lk77 Oct 04 '22 at 09:12
  • 1
    `run dev` is often a long running/server process that doesn't exit, more so in the `webpack`/`vite` case. I was just noting that for that case, the problem requires a different solution. – Matt Oct 05 '22 at 00:02

2 Answers2

3

There is another solution using concurrently npm package

first install concurrently (you can install it globally)

npm i concurrently -g

then run

concurrently "php artisan serve" "npm run dev"

or you can use it as package.json script

1 : update you package json like this

    "scripts": {
        "dev": "vite",
        "build": "vite build ",
        "start": "concurrently  \"php artisan config:cache\" \"php artisan serve\" \"npm run dev \"  "
    },

2 : in terminal run npm start

dante velli
  • 369
  • 1
  • 13
0

Yes. There is a creative way You should define a variable in your command line İf you're using linux run this command:

export part="php $PWD/artisan serve"

Note:part is variable name. Name it whatever you want (part stands for php artisan)

Note:by running this command the variable will accessible just in that CMD window. That means this way is a temporary way and if you want to access it all the time you need to add this command to your .bash or .profile file