A plugin for running commands when files change or when Vite starts.
npm i -D vite-plugin-run
Install vite-plugin-run
and add it to your Vite configuration:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import laravel from 'vite-plugin-laravel'
import run from 'vite-plugin-run'
export default defineConfig({
plugins: [
laravel(),
vue(),
run([
{
startup: true,
name: 'typescript transform',
run: ['php', 'artisan', 'typescript:transform'],
condition: (file) => file.includes('Data.php'),
},
{
startup: true,
name: 'build routes',
run: ['php', 'artisan', 'routes:generate'],
condition: (file) => file.includes('/routes/'),
}
]),
],
})
When a file in your project changes, its path will be given as an argument to condition
. If the function returns true
, a shell command described by run
will be executed.
Option | Type | Description | Default |
---|---|---|---|
silent |
bool |
Whether to hide the commands output in the console | true |
skipDts |
bool |
Whether to skip HMR reloads when a .d.ts file changes |
true |
input |
Runner[] |
List of runners | [] |
Optionally, you can directly pass a runner or a list of runner to the plugin options.
Option | Type | Description | Default |
---|---|---|---|
startup |
bool |
Whether the command should run when Vite starts | false |
name |
string |
An identifier for the runner, used in logs | |
condition |
() => boolean |
A function that should return true for a file change to execute the runner | |
run |
() => string[] or string[] |
A command executed when a file changed and the condition matches | |
onFileChanged |
() =>void |
A callback executed when a file changed and the condition matches | |
delay |
number |
Delay before the command is executed | 50 |
·
Built with ❤︎ by Enzo Innocenzi