amirilovic / vite-plugin-on-success

Vite plugin to run a command after build

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vite-plugin-on-success

Plugin adds functionally to run a command once vite build is done. This can be useful if you are using vite to build node server and you want to run for example node index.js after vite build.

Usage

Install the package:

$ npm install -D vite-plugin-on-success

Add it to your vite.config.ts:

import { defineConfig } from "vite";
import { onSuccess } from "vite-plugin-on-success";

export default defineConfig({
  build: {
    ssr: true,
    sourcemap: true,
    lib: {
      entry: "src/index.ts",
      formats: ["es"],
      fileName: "index",
    },
  },
  plugins: [onSuccess({ command: "node index.js" })],
});

Run vite build:

$ vite build --watch

=> node index.js is executed after build is done.

Using Environment Variable

Plugin also works with VITE_ON_SUCCESS environment variable.

Add the plugin to your vite config without on success command like:

import { defineConfig } from "vite";
import { onSuccess } from "vite-plugin-on-success";

export default defineConfig({
  build: {
    ssr: true,
    sourcemap: true,
    lib: {
      entry: "src/index.ts",
      formats: ["es"],
      fileName: "index",
    },
  },
  plugins: [onSuccess()], // no command specified
});

Run vite build with environment variable like:

$ VITE_ON_SUCCESS='node dist/index.js' vite build --watch

About

Vite plugin to run a command after build

License:MIT License


Languages

Language:TypeScript 100.0%