sSeewald

payload plugin template

by sSeewald
Testing & developer experience
v3
>=3.0.0 <4.0.0
MIT

Overview

Summary generated from the README

A fork of the official Payload plugin template for creating Payload v3 plugins in TypeScript. It ships a development Payload app with hot reloading, example server and client components, and a sample custom endpoint. It also includes Jest and Playwright tests, Docker setup, and a build step that turns @ aliases into package exports and generates the import map. Requires Payload 3.x, Node.js 18+ and pnpm.

Features

  • Dev Payload app with hot reloading alongside the plugin source
  • Example server and client admin components
  • Example custom API endpoint
  • Jest unit tests and Playwright end-to-end tests
  • Docker setup for containerized development with MongoDB
  • Build-time @ alias resolution that generates exports and the import map

Use cases

  • Bootstrap a new Payload v3 plugin with a working dev environment
  • Learn how to structure plugin components, endpoints and tests
  • Publish a typed plugin package to npm with generated exports

From the author

Payload plugin template using v3

Installation

npm i payload-plugin-template

7

Stars

0

Forks

0

Open Issues

1 years ago

Last Updated

0

Weekly Downloads

v

npm Version

Dependencies

GitHub stars

70 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20267
Dec 4, 20267
Dec 3, 20267
Dec 2, 20267
Dec 1, 20267
Nov 30, 20267
Nov 29, 20267
Nov 28, 20267
Nov 27, 20267
Nov 26, 20267
Nov 25, 20267
Nov 24, 20267
Nov 23, 20267
Nov 22, 20267
Nov 21, 20267
Nov 20, 20267
Nov 19, 20267
Nov 18, 20267
Nov 17, 20267
Nov 16, 20267
Nov 15, 20267
Nov 14, 20267
Nov 13, 20267
Nov 12, 20267
Nov 11, 20267
Nov 10, 20267
Nov 9, 20267
Nov 8, 20267
Nov 7, 20267
Nov 6, 20267
Nov 5, 20267
Nov 4, 20267
Nov 3, 20267
Nov 2, 20267
Nov 1, 20267
Oct 31, 20267
Oct 30, 20267
Oct 29, 20267
Oct 28, 20267
Oct 27, 20267
Oct 26, 20267
Oct 25, 20267
Oct 24, 20267
Oct 23, 20267
Oct 22, 20267
Oct 21, 20267
Oct 20, 20267
Oct 19, 20267
Oct 18, 20267
Oct 17, 20267
Oct 16, 20267
Oct 15, 20267
Oct 14, 20267
Oct 13, 20267
Oct 12, 20267
Oct 11, 20267
Oct 10, 20267
Oct 9, 20267
Oct 8, 20267
Oct 7, 20267
Oct 6, 20267
Oct 5, 20267
Oct 4, 20267
Oct 3, 20267
Oct 2, 20267
Oct 1, 20267
Sep 30, 20267
Sep 29, 20267
Sep 28, 20267
Sep 27, 20267
Sep 26, 20267
Sep 25, 20267
Sep 24, 20267
Sep 23, 20267
Sep 22, 20267
Sep 21, 20267
Sep 20, 20267
Sep 19, 20267
Sep 18, 20267
Sep 17, 20267
Sep 16, 20267
Sep 15, 20267
Sep 14, 20267
Sep 13, 20267
Sep 12, 20267
Sep 11, 20267
Sep 10, 20267
Sep 9, 20267
Sep 8, 20267
Sep 7, 20267
Sep 6, 20267
npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

19/100Poor

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1040043789-root.svg)](https://payloaddirectory.dev/plugins/1040043789-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1040043789-root"><img src="https://payloaddirectory.dev/badge/1040043789-root.svg" alt="Payload Directory"></a>
Updated Aug 25, 2025Created Aug 18, 2025

README

Payload v3 Plugin Template

author License: MIT TypeScript Payload CMS

CI Forked From

This is a fork of the official Payload Plugin Template Special thanks to the amazing team at Payload CMS for creating this excellent foundation for plugin development.

A modern, production-ready template for creating Payload CMS plugins with TypeScript, React, and comprehensive testing.

Features

  • Complete Development Environment: Pre-configured with hot-reloading, TypeScript, and ESLint
  • Docker Support: Ready-to-use Docker setup for containerized development
  • Comprehensive Testing: Jest test suite with examples for components, endpoints, and integration tests
  • Example Components: Server and Client component examples demonstrating Payload's architecture
  • Custom Endpoints: Example API endpoint implementation
  • Cross-platform: Works on Windows, macOS, and Linux
  • Modern Tooling: Uses pnpm workspaces, Next.js 15, and React 19

Quick Start

Prerequisites

  • Node.js 18+ and pnpm 8+
  • Docker (optional, for containerized development)

Installation

  1. Clone this repository:
git clone https://github.com/yourusername/payload-plugin-template.git
cd payload-plugin-template
  1. Install dependencies:
pnpm install
  1. Start development:
pnpm dev

This will:

  • Watch and compile the plugin source code
  • Start the development Payload app at http://localhost:3000
  • Enable hot-reloading for both plugin and app code

Project Structure

payload-plugin-template/
├── src/                    # Plugin source code
│   ├── components/         # React components (Server & Client)
│   ├── endpoints/          # Custom API endpoints
│   ├── __tests__/          # Jest test suites
│   ├── plugin.ts           # Main plugin configuration
│   └── index.ts            # Plugin exports
├── dev/                    # Development Payload app
│   ├── src/
│   │   ├── app/            # Next.js app directory
│   │   └── payload.config.ts
│   └── package.json
├── dist/                   # Compiled plugin output
└── package.json            # Plugin package configuration

Development

Available Scripts

CommandDescription
pnpm devStart development with hot-reloading
pnpm buildBuild the plugin for production
pnpm testRun the test suite
pnpm lintLint the codebase
pnpm dev:dockerStart development with Docker

Docker Development

For containerized development with MongoDB:

# Start Docker environment
pnpm dev:docker

# Stop containers
cd dev && pnpm docker:down

# Clean volumes
cd dev && pnpm docker:clean

Testing

The template includes comprehensive test examples with both unit and E2E testing:

Unit Tests (Jest)
# Run all unit tests
pnpm test

# Watch mode
pnpm test:watch

# Coverage report
pnpm test:coverage

Test files are located in src/__tests__/ and cover:

  • Plugin initialization
  • React components (Server & Client)
  • Custom endpoints
  • Integration scenarios
E2E Tests (Playwright)
# Run E2E tests (requires dev server running)
pnpm test:e2e

# Run E2E tests with UI
pnpm test:e2e:ui

# Run specific test file
pnpm test:e2e admin-components.spec.ts

E2E test files are located in e2e/tests/ and cover:

  • Admin dashboard components interaction
  • API endpoint functionality
  • GraphQL queries
  • User interface workflows

Note: Playwright is configured to use an existing dev server on port 3000. Make sure to run pnpm dev before running E2E tests.

Building Your Plugin

1. Update Package Information

Edit package.json with your plugin details:

{
  "name": "payload-plugin-your-name",
  "description": "Your plugin description",
  "author": "Your Name",
  "license": "MIT"
}

2. Configure the Plugin

The main plugin file is src/plugin.ts:

export const yourPlugin = (pluginOptions: PluginTypes) =>
  (incomingConfig: Config): Config => {
    let config = { ...incomingConfig }

    // Extend collections
    config.collections = [
      ...(config.collections || []),
      // Your collections
    ]

    // Add custom endpoints
    config.endpoints = [
      ...(config.endpoints || []),
      // Your endpoints
    ]

    return config
  }

3. Add Components

Create Server and Client components in src/components/:

Server Component (runs during SSR):

export const MyServerComponent: PayloadServerReactComponent = () => {
  // Has access to server-side resources
  return <div>Server Component</div>
}

Client Component (runs in browser):

'use client'
export const MyClientComponent: PayloadClientReactComponent = () => {
  // Can use hooks and browser APIs
  const [state, setState] = useState()
  return <div>Client Component</div>
}

4. Create Endpoints

Add custom API endpoints in src/endpoints/:

export const myEndpoint: Endpoint = {
  path: '/my-endpoint',
  method: 'get',
  handler: async (req) => {
    return Response.json({ message: 'Hello!' })
  }
}

Using @ Aliases for Exports

The plugin template includes an automatic @ alias transformation system that simplifies how you reference your components and utilities in the plugin configuration.

How It Works

When you use @ aliases in your plugin code (like @components/MyComponent), the build process automatically:

  1. Tracks all @ alias usage in your TypeScript files
  2. Resolves them to the correct file paths
  3. Generates an exports.js file with all necessary exports
  4. Transforms the @ aliases to proper package imports (payload-plugin-template/exports#MyComponent)

@ Alias Patterns

// In your plugin configuration (src/index.ts or similar)
config.admin.components = {
  afterDashboard: [
    // Named export from a specific path
    '@components/AfterDashboard#AfterDashboard',
    
    // Named export using shorthand (assumes export name matches last path segment)
    '@components#AfterDashboardClient',
    
    // Default export (automatically detected)
    '@example/exampleComponent',
    
    // Nested paths work too
    '@utils/helpers/formatter#formatDate'
  ]
}

Path Resolution

The @ alias paths map directly to your file structure:

@ AliasResolves ToExport
@components/MyComponentdist/components/MyComponent.js or dist/components/MyComponent/index.jsNamed or default export MyComponent
@components#MyComponentdist/components/index.jsNamed export MyComponent
@utils/helper#formatdist/utils/helper.js or dist/utils/helper/index.jsNamed export format

Default vs Named Exports

The system automatically detects whether your module uses default or named exports:

// Default export (src/example/Component.tsx)
export default function Component() { ... }
// Use: '@example/Component'

// Named export (src/components/index.ts)
export const MyComponent = () => { ... }
// Use: '@components#MyComponent'

Build-Time Validation

During the build process, if an @ alias can't be resolved, you'll see a clear error message:

❌ ERROR: Could not resolve @ alias: @components/NonExistent
   Tried paths:
     - dist/components/NonExistent.js
     - dist/components/NonExistent/index.js
   Check if the file exists or if the @ alias path matches the actual file structure

This helps catch typos and incorrect paths early in the development process.

Benefits

  • Type Safety: TypeScript still validates your exports
  • Automatic Export Generation: No need to manually maintain export files
  • Auto-Generated Import Map: Automatically generates importMap.js on build changes
  • CSS/SCSS Support: Full support for CSS and SCSS modules with automatic compilation
  • Clear Error Messages: Build-time validation catches issues early
  • Flexible Patterns: Support for both named and default exports
  • Direct Path Mapping: Intuitive mapping from @ aliases to file structure

Publishing

  1. Build your plugin:
pnpm build
  1. Publish to npm:
npm publish
  1. Users can then install your plugin:
pnpm add your-plugin-name

Best Practices

  • Always spread existing config arrays/objects to preserve data
  • Provide TypeScript types for all plugin options
  • Include comprehensive tests
  • Add an enable/disable option
  • Document all configuration options
  • Use Semantic Versioning
  • Tag your repository with payload-plugin

Resources

License

MIT - See LICENSE for details

Questions & Support


Built with ❤️ using Payload CMS

Similar plugins