https://github.com/innocenzi/vite-plugin-run
Run commands when Vite starts or a file changes
https://github.com/innocenzi/vite-plugin-run
Last synced: 5 months ago
JSON representation
Run commands when Vite starts or a file changes
- Host: GitHub
- URL: https://github.com/innocenzi/vite-plugin-run
- Owner: innocenzi
- Created: 2022-07-08T13:25:29.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-18T15:34:18.000Z (11 months ago)
- Last Synced: 2025-05-08T23:48:19.266Z (5 months ago)
- Language: TypeScript
- Homepage:
- Size: 178 KB
- Stars: 83
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Runner plugin for Vite
A plugin for running commands when files change or when Vite starts.
npm i -D vite-plugin-run
## Usage
Install `vite-plugin-run` and add it to your Vite configuration:
```ts
import { run } from 'vite-plugin-run'export default defineConfig({
plugins: [
laravel(),
vue(),
run([
{
name: 'typescript transform',
run: ['php', 'artisan', 'typescript:transform'],
pattern: ['app/**/*Data.php', 'app/**/Enums/**/*.php'],
},
{
name: 'build routes',
run: ['php', 'artisan', 'routes:generate'],
condition: (file) => file.includes('/routes/'),
}
]),
],
})
```You can either use a `pattern` or a `condition` to specify how the files changes should be detected.
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.
## Plugin options
| 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.
## Runner options
| Option | Type | Description | Default |
| --------------- | ------------------------------ | -------------------------------------------------------------------------- | ------- |
| `startup` | `bool` | Whether the command should run when Vite starts | `true` |
| `build` | `bool` | Whether the command should run when Vite builds | `true` |
| `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 | |
| `pattern` | `string` or `string[]` | A minimatch pattern which files must match | |
| `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` |
| `throttle` | `number` | Delay before the command can be re-executed | `50` |
·
Built with ❤︎ by Enzo Innocenzi