Agent skill

smith-nuxt

Nuxt 3 development patterns including auto-import stubbing for tests, environment variable conventions, and middleware testing. Use when working with Nuxt projects, testing Nuxt components/middleware, or configuring Nuxt environment variables.

Stars 1
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/tianjianjiang/smith/tree/main/smith-nuxt

SKILL.md

Nuxt Development Standards

  • Scope: Nuxt 3 specific patterns
  • Load if: Working with Nuxt projects
  • Prerequisites: @smith-principles/SKILL.md, @smith-standards/SKILL.md, @smith-typescript/SKILL.md

CRITICAL: Auto-Import Stubbing (Primacy Zone)

Stub Nuxt auto-imports BEFORE importing modules that use them - module code executes at import time.

  • Mocking h3 module expecting auto-imports (they're globals)
  • Importing middleware before stubbing globals

Auto-Import Stubbing in Tests

Nuxt auto-imports utilities like defineEventHandler, createError, useState. These are globally available in Nuxt runtime but NOT in test environments.

Stub auto-imports globally BEFORE importing the module under test:

typescript
import { describe, it, expect, vi } from 'vitest';
import type { H3Event } from 'h3';

// Stub Nuxt auto-imports BEFORE any imports that use them
(globalThis as Record<string, unknown>).defineEventHandler =
  (handler: (event: H3Event) => unknown) => handler;
(globalThis as Record<string, unknown>).createError =
  (options: { statusCode: number; statusMessage: string }) =>
    Object.assign(new Error(options.statusMessage), { statusCode: options.statusCode });

// Now import the module that uses auto-imports
import middleware from '../myMiddleware';
  • NEVER mock h3 module expecting auto-imports to work (they're globals, not module exports)
  • NEVER import middleware before stubbing globals (module executes at import time)

Environment Variables

Nuxt uses NUXT_ prefix for runtime config environment variables.

  • NUXT_PUBLIC_* - Exposed to client
  • NUXT_* - Server-only

Server-only:

shell
NUXT_DATABASE_URL=postgres://...
NUXT_API_SECRET=secret

Public (exposed to browser):

shell
NUXT_PUBLIC_API_BASE=https://api.example.com
  • @smith-typescript/SKILL.md - General TypeScript patterns
  • @smith-tests/SKILL.md - Testing standards

ACTION (Recency Zone)

Before testing Nuxt code:

  1. Stub auto-imports BEFORE any imports
  2. Use NUXT_PUBLIC_* for client-exposed env vars
  3. Use NUXT_* for server-only env vars

Expand your agent's capabilities with these related and highly-rated skills.

tianjianjiang/smith

smith-style

File naming, path standards, and conventional commits. Use when naming files, creating branches, writing commit messages, or setting up new projects. Covers underscore vs hyphen conventions, commit format, and branch naming patterns.

1 0
Explore
tianjianjiang/smith

smith-stacks

Stacked pull request workflows for large features. Use when creating stacked PRs, managing dependent PRs, or rebasing after parent merges. Covers stack creation, merge order, and squash merge handling.

1 0
Explore
tianjianjiang/smith

smith-python

Python development with uv, pytest, ruff, and type hints. Use when writing Python code, running tests, managing Python packages, or working with virtual environments. Covers import organization, type hints, pytest patterns, and environment variables.

1 0
Explore
tianjianjiang/smith

smith-principles

Fundamental coding principles (DRY, KISS, YAGNI, SOLID, HHH). Use when starting any development task, evaluating implementation approaches, or reviewing code quality. Always active as foundation for all development decisions.

1 0
Explore
tianjianjiang/smith

smith-plan

Plan tracking protocol (portable). Progress tracking with checkboxes, iteration workflow, completion/blocker signals. Use when executing multi-step plans, tracking task progress, or working from plan files. IMPORTANT - Always update the plan file after completing tasks.

1 0
Explore
tianjianjiang/smith

smith-analysis

Reasoning frameworks and problem decomposition techniques. Use when planning implementation, evaluating arguments, estimating scope, decomposing complex tasks, or applying first principles thinking.

1 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results