Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emargareten/vite-plugin-command
Vite plugin to run custom commands on file changes
https://github.com/emargareten/vite-plugin-command
command vite vite-plugin
Last synced: 1 day ago
JSON representation
Vite plugin to run custom commands on file changes
- Host: GitHub
- URL: https://github.com/emargareten/vite-plugin-command
- Owner: emargareten
- License: mit
- Created: 2023-02-20T12:27:11.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-17T22:38:57.000Z (5 months ago)
- Last Synced: 2025-01-02T10:12:53.862Z (about 1 month ago)
- Topics: command, vite, vite-plugin
- Language: TypeScript
- Homepage:
- Size: 259 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Vite Command Runner
A Vite plugin that runs custom shell commands on file changes.
## Installation
You can install the package via `npm`:
```bash
npm i -D vite-plugin-command
```## Usage
Import the package from `vite.config.js` and configure it.
```js
import { defineConfig } from "vite"
import { command } from "vite-plugin-command"export default defineConfig({
plugins: [
command({
pattern: "routes/**/*.php",
run: "php artisan ziggy:generate",
}),
],
})
```You can also run multiple commands by passing an array of objects.
```js
export default defineConfig({
plugins: [
command([
{
pattern: "routes/**/*.php",
run: "php artisan ziggy:generate",
},
{
pattern: "app/{Data,Enums}/**/*.php",
run: "php artisan typescript:transform",
},
]),
],
})
```Once a tracked file changes, the plugin will execute the specified command.
## Plugin options
| name | type | description | default |
|----------------|----------------------------------|--------------------------------------------------------------------------------------------------------|---------|
| `pattern` | `string` or `string[]` | Tracked files paths (minimatch pattern) | |
| `run` | `string` | The command to be executed | |
| `silent` | `boolean` | Hide the command output in the console | `false` |
| `throttle` | `number` | Delay before the command can be re-executed (in milliseconds) | `500` |
| `startup` | `boolean` | Run the command when Vite starts | `true` |
| `customOutput` | `string` or `(output) => string` | Display a custom output in the console after command ran (when set, the command output will be hidden) | |## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.