Skip to content

Instantly share code, notes, and snippets.

@n-ce
Last active April 10, 2024 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n-ce/e4b7660422f0dfa61d3e9ddd73097d28 to your computer and use it in GitHub Desktop.
Save n-ce/e4b7660422f0dfa61d3e9ddd73097d28 to your computer and use it in GitHub Desktop.
Using Eruda with Vite (+ TypeScript)
npm i eruda -D

To use eruda without installing eruda as a package, edit the src in the plugin to https://cdn.jsdelivr.net/npm/eruda.

vite.config.ts

import { defineConfig } from "vite";
import type { PluginOption } from 'vite'

const injectEruda = (serve: boolean) => serve ? (<PluginOption>{
  name: 'erudaInjector',
  transformIndexHtml: html => ({
    html,
    tags: [
      {
        tag: 'script',
        attrs: {
          src: '/node_modules/eruda/eruda'
        },
        injectTo: 'body'
      },
      {
        tag: 'script',
        injectTo: 'body',
        children: 'eruda.init()'
      }
    ]
  })
}) : [];



export default defineConfig(({ command }) =>
  ({ plugins: [erudaInjector(command==='serve')] })
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment