Skip to content

Instantly share code, notes, and snippets.

@n-ce
Last active May 11, 2024 09:52
Show Gist options
  • 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)
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