Vite Plugin Development

v1.0.0

Use when developing Vite plugins: scaffolding plugin structure, implementing hooks (transform, resolveId, load, buildStart, etc.), handling virtual modules,...

0· 75·0 current·0 all-time
byHjs102468@goldath

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for goldath/vite-plugin-dev.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "Vite Plugin Development" (goldath/vite-plugin-dev) from ClawHub.
Skill page: https://clawhub.ai/goldath/vite-plugin-dev
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Canonical install target

openclaw skills install goldath/vite-plugin-dev

ClawHub CLI

Package manager switcher

npx clawhub@latest install vite-plugin-dev
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
Name/description (Vite plugin development) align with the provided content: scaffolding, hook patterns, HMR, SSR, testing, and publishing. The skill declares no binaries, env vars, or installs, which is reasonable for a docs/instruction-only skill.
Instruction Scope
SKILL.md stays on-topic and provides code patterns and checklists for plugin authors. Two patterns merit attention: (1) virtual modules and build-info examples read process.env (e.g., npm_package_version, NODE_ENV) and could expose env values to client code if copied verbatim; (2) dev-server middleware examples create local HTTP endpoints, which is expected in dev but should not be used to expose secrets or production data. The instructions do not tell the agent to read arbitrary system files, external endpoints, or transmit data off-host.
Install Mechanism
No install spec and no code files that would be written/executed by an installer. Instruction-only skills are lowest risk for install-time code execution.
Credentials
The skill requests no environment variables or credentials. However, examples show accessing process.env and injecting config into client code; plugin authors must avoid embedding secrets into virtual modules or define/config injection. The examples themselves are not requesting credentials, but they show patterns that could accidentally leak sensitive env values if misused.
Persistence & Privilege
always is false, no persistence or system-wide configuration changes are requested, and the skill does not instruct modification of other skills or global agent settings.
Assessment
This is a documentation-style skill for developing Vite plugins and is internally consistent. It does not request credentials or perform any installs. Before using or copying example code into real projects, be careful not to: (1) expose sensitive environment variables via virtual modules or define injections (avoid using process.env values that contain secrets), (2) publish dev-only middleware or endpoints to production, and (3) blindly copy examples that embed build-time env values into client bundles. If the skill later included code that read arbitrary file paths, required cloud credentials, or fetched remote installers, that would raise suspicion—review any added code files or install steps before installing or executing them.

Like a lobster shell, security has layers — review code before you run it.

latestvk9768b9zvfzef0rn4e51tkggzx84znk4
75downloads
0stars
1versions
Updated 1w ago
v1.0.0
MIT-0

Vite Plugin Development

When to Use

  • Building a custom Vite plugin from scratch
  • Implementing transform/resolve hooks for special file types
  • Creating virtual modules or runtime injections
  • Adding HMR (Hot Module Replacement) support
  • Making plugins SSR-compatible
  • Publishing a plugin package to npm

Core Workflow

1. Plugin Scaffold

Every Vite plugin is a factory function returning a plugin object:

import type { Plugin } from 'vite'

export interface MyPluginOptions {
  include?: string | RegExp | (string | RegExp)[]
  exclude?: string | RegExp | (string | RegExp)[]
}

export default function myPlugin(options: MyPluginOptions = {}): Plugin {
  return {
    name: 'vite-plugin-my',          // required, unique name
    enforce: 'pre',                   // 'pre' | 'post' | undefined
    apply: 'build',                   // 'build' | 'serve' | ((config, env) => bool)

    // lifecycle hooks below...
  }
}

2. Key Hooks

HookPhasePurpose
configBothModify resolved config
configResolvedBothRead final config
buildStartBothInitialize plugin state
resolveIdBothCustom module resolution
loadBothCustom module content
transformBothCode transformation
generateBundleBuildPost-process output
configureServerServeExtend dev server
handleHotUpdateServeCustom HMR logic

3. Transform Hook Pattern

transform(code, id) {
  if (!id.endsWith('.myext')) return null  // return null = skip
  const transformed = doTransform(code)
  return {
    code: transformed,
    map: null,  // provide sourcemap when possible
  }
},

4. Virtual Modules

const VIRTUAL_ID = 'virtual:my-module'
const RESOLVED_ID = '\0' + VIRTUAL_ID   // prefix \0 to avoid collisions

resolveId(id) {
  if (id === VIRTUAL_ID) return RESOLVED_ID
},
load(id) {
  if (id === RESOLVED_ID) {
    return `export const data = ${JSON.stringify(myData)}`
  }
},

5. HMR Support

handleHotUpdate({ file, server }) {
  if (file.endsWith('.myext')) {
    server.ws.send({ type: 'full-reload' })
    return []  // prevent default HMR
  }
},

6. SSR Compatibility Checklist

  • Check options.ssr in transform / load hooks
  • Avoid browser-only APIs at transform time
  • Mark side-effect-free modules: set moduleSideEffects: false
  • Test with vite build --ssr

7. Testing Strategy

// Use vite's createServer for integration tests
import { createServer } from 'vite'
const server = await createServer({ plugins: [myPlugin()] })
const mod = await server.ssrLoadModule('/src/test.myext')

Publishing Checklist

  • package.json main + module + types fields set
  • peerDependencies: "vite": "^5.0.0 || ^6.0.0"
  • README with usage example + options table
  • Export TypeScript types
  • Test against Vite 5 and 6
  • vite-plugin- prefix in package name (ecosystem convention)

Comments

Loading comments...