stacks-plugins

$npx mdskill add stacksjs/stacks/stacks-plugins

Create and manage Stacks framework plugins for Bun and Vite.

  • Extend build/serve capabilities with custom Bun or Vite plugins.
  • Depends on @stacksjs/plugins package and Bun plugin API.
  • Uses plugin factory and type definitions to guide plugin creation.
  • Provides preloader configuration and plugin registration functions.

SKILL.md

.github/skills/stacks-pluginsView on GitHub ↗
---
name: stacks-plugins
description: Use when working with the Stacks plugin system — Bun plugins, Vite plugins, preloader, or extending the framework's build/serve capabilities. Covers @stacksjs/plugins.
license: MIT
compatibility: Bun >= 1.3.0, TypeScript
allowed-tools: Read Edit Write Bash Grep Glob
---

# Stacks Plugins

## Key Paths
- Core package: `storage/framework/core/plugins/src/`
- Source: `storage/framework/core/plugins/src/index.ts`
- Preloader: `storage/framework/defaults/resources/plugins/preloader.ts`
- Package: `@stacksjs/plugins`

## API

```typescript
import { plugin } from '@stacksjs/plugins'
import type { BunPlugin, VitePlugin } from '@stacksjs/plugins'
```

The package exports:
- `plugin` — Bun's native plugin factory for creating Bun plugins
- `BunPlugin` — Type definition for Bun plugins
- `VitePlugin` — Type definition for Vite plugins

## Creating a Bun Plugin

```typescript
import { plugin } from '@stacksjs/plugins'
import type { BunPlugin } from '@stacksjs/plugins'

const myPlugin: BunPlugin = {
  name: 'my-plugin',
  setup(build) {
    build.onLoad({ filter: /\.custom$/ }, async (args) => {
      const content = await Bun.file(args.path).text()
      return { contents: transformContent(content), loader: 'ts' }
    })
  },
}

plugin(myPlugin)
```

## Preloader

The framework preloader at `storage/framework/defaults/resources/plugins/preloader.ts` runs before the application starts:

- Configured in `bunfig.toml`: `preload = ["./storage/framework/defaults/resources/plugins/preloader.ts"]`
- Loads `bun-plugin-stx` for STX template processing
- Initializes auto-imports and framework globals

## Gotchas
- **Thin wrapper** — re-exports Bun's `plugin` factory and types for both Bun and Vite
- **Preloader is critical** — the STX plugin (`bun-plugin-stx`) must be preloaded for template processing to work
- **Two plugin systems** — Bun plugins (runtime) and Vite plugins (build) are different APIs
- **Plugins must be Bun-compatible** — Node.js plugins won't work without adaptation
- **Plugin preloader runs before app** — any setup in preloader.ts happens before any application code

More from stacksjs/stacks

SkillDescription
stacks-actionsUse when working with Stacks server actions — creating actions in app/Actions/, auto-generated API actions from the useApi model trait, the 80+ default framework actions (auth, dashboard, commerce, content, deployment, jobs), action request/response handling, or action registration. Covers @stacksjs/actions and storage/framework/defaults/actions/.
stacks-aiUse when integrating AI capabilities into a Stacks application — using Anthropic/OpenAI/Ollama/AWS Bedrock drivers, image generation (DALL-E), vision analysis, RAG/vector search, embeddings, MCP (Model Context Protocol) clients, text summarization, sentiment analysis, content classification, personalization, or the buddy AI assistant. Covers @stacksjs/ai and config/ai.ts.
stacks-aliasUse when working with path aliases in a Stacks project — import resolution, module aliasing, or debugging import paths. Covers @stacksjs/alias which defines 260+ path mappings for the entire framework.
stacks-analyticsUse when adding analytics to a Stacks application — configuring Fathom or self-hosted analytics, generating tracking scripts, privacy-friendly analytics setup, or the analytics configuration. Covers @stacksjs/analytics and config/analytics.ts.
stacks-apiUse when building, modifying, or debugging API endpoints in a Stacks application — defining routes, handling requests, API middleware, working with the API server, HTTP client (fetcher), API resources, or OpenAPI generation. Covers both @stacksjs/api utilities and the stacks-api server implementation.
stacks-arraysUse when working with array utilities in Stacks — statistical operations (average, median, mode, standard deviation, z-score, percentile, covariance), array manipulation (unique, flatten, partition, shuffle, sample, move), containment checks, or the Arr facade. Covers @stacksjs/arrays.
stacks-authUse when implementing authentication, authorization, passkeys, TOTP/2FA, RBAC, gates, policies, session auth, token management, email verification, password resets, or rate limiting in a Stacks application. Covers the @stacksjs/auth package, config/auth.ts, app/Gates.ts, and app/Middleware/.
stacks-auto-importsUse when working with the Stacks auto-import system — understanding how browser and server auto-imports work, configuring auto-imported functions/models/composables, the auto-import manifests, type generation, or how globals are injected. Covers the auto-import pipeline at storage/framework/auto-imports/.
stacks-brandkitUse when defining or exploring a brand identity for a Stacks project and you want premium brand-kit REFERENCE IMAGES first - logo directions, palettes, typography specimens, identity boards, and application/mockup decks. Generates IMAGES ONLY, never code. Trained for minimalist, cinematic, editorial, dark-tech, luxury, cultural, security, gaming, developer-tool, and consumer-app brand systems with intentional logo concepting, sparse type, strong symbolic meaning, and disciplined palettes a coding step can build against.
stacks-browseUse for headless browser QA on Stacks applications — navigation, screenshots, responsive testing, console/network monitoring, and accessibility snapshots. Dependency-free: drives a system browser over the Chrome DevTools Protocol using only Bun (no Playwright/Puppeteer). Invoke with /stacks-browse.