Index of every page on this site: llms.txt
All skills
onmax avatar

/nuxt-modules

@2e74504 official
by Maxonmax/nuxt-skills722 stars
38
Run it yourself

Use when creating Nuxt modules: (1) Published npm modules (@nuxtjs/, nuxt-), (2) Local project modules (modules/ directory), (3) Runtime extensions (components, composables, plugins), (4) Server extensions (API routes, middleware), (5) Releasing/publishing modules to npm, (6) Setting up CI/CD workflows for modules. Provides defineNuxtModule patterns, Kit utilities, hooks, E2E testing, and release automation.

Use this Skill: https://skilld.dev/gh/onmax/nuxt-skills/nuxt-modules

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestesting-and-publishing.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Testing & Publishing

E2E testing, best practices, and publishing modules.

E2E Testing Setup

npm install -D @nuxt/test-utils vitest
// vitest.config.ts
import { defineVitestConfig } from '@nuxt/test-utils/config'

export default defineVitestConfig({
  test: { environment: 'nuxt' }
})

Test Fixtures

Create a minimal Nuxt app that uses your module:

// test/fixtures/basic/nuxt.config.ts
import MyModule from '../../../src/module'

export default defineNuxtConfig({
  modules: [MyModule],
  myModule: { enabled: true }
})
<!-- test/fixtures/basic/pages/index.vue -->
<template>
  <MyButton>Click me</MyButton>
</template>

Writing Tests

import { fileURLToPath } from 'node:url'
import { $fetch, setup } from '@nuxt/test-utils/e2e'
// test/basic.test.ts
import { describe, expect, it } from 'vitest'

describe('basic', async () => {
  await setup({
    rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url))
  })

  it('renders component', async () => {
    const html = await $fetch('/')
    expect(html).toContain('Click me')
  })

  it('api works', async () => {
    const data = await $fetch('/api/_my-module/status')
    expect(data).toEqual({ status: 'ok' })
  })
})

Manual Testing

# In module directory
npm pack

# In test project
npm install /path/to/my-module-1.0.0.tgz

Best Practices

Async Setup

Keep setup fast. Use debug: { modules: true } to inspect module setup timing. Nuxt's slow-setup warning threshold depends on the release, so check the supported version when interpreting it.

// This fetch delays module setup
async setup(options, nuxt) {
  const data = await fetchRemoteConfig()  // Slow!
}

// This moves the wait to ready, which Nuxt also awaits
setup(options, nuxt) {
  nuxt.hook('ready', async () => {
    const data = await fetchRemoteConfig()
  })
}

Choose the lifecycle phase that needs the result. Moving awaited work to ready does not remove it from initialization. To reduce startup work, avoid unnecessary I/O and repeated computation, then check overall startup as well as module setup timing.

Prefix All Exports

Avoid naming conflicts:

Type Wrong Right
Components <Button> <FooButton>
Composables useData() useFooData()
Server routes /api/track /api/_foo/track
Plugins $helper $fooHelper

Lifecycle Hooks

For installation and upgrade tasks:

export default defineNuxtModule({
  meta: { name: 'my-module', version: '2.0.0' },

  async onInstall(nuxt) {
    await generateInitialConfig(nuxt.options.rootDir)
  },

  async onUpgrade(nuxt, options, previousVersion) {
    if (semver.lt(previousVersion, '2.0.0')) {
      await migrateFromV1()
    }
  }
})

Nuxt stores lifecycle state in the project's .nuxtrc, under meta.name with meta.version as the recorded version. Missing state can make installation work run again, so initialization and migrations must tolerate repeat execution. Keep repeatable generated build output in normal setup or template generation. Lifecycle errors are logged without stopping the build; do not assume a failed required migration prevents setup from continuing.

TypeScript + ESM Only

// Always export typed options
// ESM only - no CommonJS
import { something } from 'package'

export interface ModuleOptions {
  apiKey: string
  debug?: boolean
} // Right
const { something } = require('package') // Wrong

Error Messages

setup(options, nuxt) {
  if (!options.apiKey) {
    throw new Error('[my-module] `apiKey` option is required')
  }
}

Releasing

Two-step: local bump → CI publish. CI must pass before tag push.

Setup

pnpm add -D bumpp
{
  "scripts": {
    "release": "bumpp && git push --follow-tags"
  }
}

Flow

pnpm release  # Prompts version, commits, tags, pushes
# → CI release.yml triggers on v* tag → npm publish + GitHub release

Commit Conventions

Prefix Bump
feat: minor
fix:, chore:, docs: patch
feat!: or BREAKING CHANGE: major

CI Workflows

Three workflows for complete CI/CD:

File Trigger Purpose
ci.yml push/PR lint, typecheck, test
pkg.yml push/PR preview packages via pkg-pr-new
release.yml tag v* npm publish + GitHub release

Copy templates from: ci-workflows.md


Publishing

Naming Conventions

Scope Example Description
@nuxtjs/ @nuxtjs/tailwindcss Community modules (nuxt-modules org)
nuxt- nuxt-my-module Third-party modules
@org/ @myorg/nuxt-auth Organization scoped

Documentation Checklist

  • Why - What problem does this solve?
  • Installation - How to install and configure?
  • Usage - Basic examples
  • Options - All config options with types
  • Demo - StackBlitz link

Version Compatibility

meta: {
  compatibility: { nuxt: '>=3.0.0' }
}

Use "X for Nuxt" naming, not "X for Nuxt 3" — let meta.compatibility handle versions.

Resources

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts10d5 checks · Risk SAFE
  • Gen Agent Trust Hub10d

    This skill is a safe and high-quality guide for Nuxt module development. It correctly implements security best practices, such as recommending OIDC for CI/CD workflows and providing safe patterns for template generation.

  • Socket10d

    No alerts

  • Snyk10d

    Risk: LOW · No issues

  • Runlayer8mo

    4 files scanned · No issues

  • ZeroLeaks6mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 2e74504. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 2 weeks ago

README badge

README badge for onmax/nuxt-skills/nuxt-modules

Instructs Claude on building Nuxt modules using defineNuxtModule, Kit utilities, and hooks to extend Nuxt with components, composables, plugins, server routes, and middleware. Covers published npm modules, local project modules, E2E testing patterns, and release automation workflows.

Generated from the current SKILL.md.

Does this skill cover local modules in the modules/ directory?
Yes. The skill covers published npm modules, local project modules in the modules/ directory, and inline modules defined in nuxt.config.ts.
What testing approach does this skill teach?
The skill provides E2E testing patterns and best practices via the testing-and-publishing reference, though you load it only when needed for your task.
Does this include CI/CD setup?
Yes. The skill includes copy-paste CI/CD workflow templates in the ci-workflows reference for automating module testing and release.
Can I use this skill to publish a module to npm?
Yes. The testing-and-publishing reference covers releasing and publishing modules to npm registries with @nuxtjs/ or nuxt- naming conventions.
Does this cover runtime extensions like components and composables?
Yes. The skill covers injecting components, composables, plugins, and server extensions (API routes, middleware) into user applications via the runtime/ directory.

Generated from the current SKILL.md. These answers refresh after source changes.