vite-plugin-instrumentation
TypeScript icon, indicating that this package has built-in type declarations

0.0.10 • Public • Published

vite-plugin-instrumentation

Inspired from NEXT.JS Instrumentation

This plugin is useful for performing asynchronous processing at the time the server starts up or during the build process.

ex: Injecting environment variables or secrets via Secret Manager

Installation

npm install -D vite-plugin-instrumentation

Usage

// vite.config.js
import { defineConfig } from "vite";
import { instrumentationPlugin } from "vite-plugin-instrumentation";

/**
 * NOTE
 * - A function that retrieves environment variables and secrets such as those from Secret Manager
 */
const fetchEnv = async () => {
  return {
    message: "MESSAGE",
  };
};

export default defineConfig({
  plugins: [
    instrumentationPlugin([
      async () => {
        console.log("Hello World!!");
      },
      async (config) => {
        const env = await fetchEnv();

        config.define = {
          ...config.define,
          __MESSAGE__: JSON.stringify(env.message),
        };
      },
    ]),
  ],
});

More details can be found here.

Package Sidebar

Install

npm i vite-plugin-instrumentation

Weekly Downloads

11

Version

0.0.10

License

MIT

Unpacked Size

5.05 kB

Total Files

9

Last publish

Collaborators

  • cut0