npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-command

v3.0.0

Published

Vite plugin to run custom commands on file changes

Readme

Vite Command Runner

A Vite plugin that runs custom shell commands on file changes.

Installation

You can install the package via npm:

npm i -D vite-plugin-command

Usage

Import the package from vite.config.js and configure it.

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.

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.

Startup commands run concurrently, and Vite waits for all enabled startup commands to finish before bundling or serving modules. If commands depend on one another, combine them in a single run string with &&.

Matching hot-update commands also run concurrently, and HMR waits for them to finish before reloading affected modules. Slow commands therefore delay hot updates.

A command never runs twice at the same time. If it is triggered again while still running, one follow-up run is queued after the current one finishes, and further triggers share that queued run. After a hot-update run starts, the command will not start again for throttle milliseconds; changes during that window queue the same single follow-up run for when it ends, so the latest change is never skipped. A hot update that arrives mid-run therefore waits for both the current and the follow-up run, and one that arrives during the throttle window waits for the rest of that window plus a run.

Set wait: false on a command to run it in the background instead, so Vite continues startup or HMR without waiting for it. This suits commands whose output Vite does not import, such as linters or notifications. Background commands never reject Vite's hooks, so failOnError has no effect when wait is false; failures are still logged unless silent is enabled.

Command failures are logged and remain non-fatal by default. Set failOnError: true on a command to reject Vite's startup or hot-update hook when it fails. Exceptions thrown by a customOutput function follow the same policy. silent suppresses raw command output and plugin error logs; Vite may still report a rejected hook when failOnError is enabled.

customOutput runs only after a command succeeds and is displayed even when silent is enabled. Failed commands report their original output unless silent is enabled.

Command output is buffered up to 10 MB; a command that prints more is treated as failed.

Upgrading from 2.x

  • Commands are now awaited: Vite waits for startup commands before bundling and for hot-update commands before HMR. This includes every rebuild in vite build --watch, since buildStart runs on each one. Set wait: false on a command to restore the 2.x fire-and-forget behavior.
  • throttle no longer drops changes: a change during the throttle window or an active run triggers one trailing run instead of being ignored.
  • Failed commands now show their stdout, and customOutput is only displayed after a successful run.

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 | Minimum delay between hot-update runs (in milliseconds); changes in between trigger one trailing run | 500 | | startup | boolean | Run the command when Vite starts | true | | failOnError | boolean | Reject Vite's startup or hot-update hook when the command fails (requires wait) | false | | wait | boolean | Wait for the command to finish before Vite continues startup or HMR | 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 for more information.