A fork of the official Payload plugin template for creating Payload 3.x plugins in TypeScript. It provides a plugin skeleton, a development Payload app with hot reloading, example server and client components, and a sample custom endpoint. Includes Jest and Playwright tests, optional Docker with MongoDB, and a build step that turns @ aliases into package exports. Requires Node.js 18+ and pnpm.
Payload plugin template using v3
Installation
npm i payload-plugin-template7
Stars
0
Forks
0
Open Issues
1 years ago
Last Updated
0
Weekly Downloads
v
npm Version
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
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
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1040043789-root)<a href="https://payloaddirectory.dev/plugins/1040043789-root"><img src="https://payloaddirectory.dev/badge/1040043789-root.svg" alt="Payload Directory"></a>README
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.
git clone https://github.com/yourusername/payload-plugin-template.git
cd payload-plugin-template
pnpm install
pnpm dev
This will:
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
| Command | Description |
|---|---|
pnpm dev | Start development with hot-reloading |
pnpm build | Build the plugin for production |
pnpm test | Run the test suite |
pnpm lint | Lint the codebase |
pnpm dev:docker | Start development with Docker |
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
The template includes comprehensive test examples with both unit and E2E testing:
# 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:
# 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:
Note: Playwright is configured to use an existing dev server on port 3000. Make sure to run pnpm dev before running E2E tests.
Edit package.json with your plugin details:
{
"name": "payload-plugin-your-name",
"description": "Your plugin description",
"author": "Your Name",
"license": "MIT"
}
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
}
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>
}
Add custom API endpoints in src/endpoints/:
export const myEndpoint: Endpoint = {
path: '/my-endpoint',
method: 'get',
handler: async (req) => {
return Response.json({ message: 'Hello!' })
}
}
The plugin template includes an automatic @ alias transformation system that simplifies how you reference your components and utilities in the plugin configuration.
When you use @ aliases in your plugin code (like @components/MyComponent), the build process automatically:
exports.js file with all necessary exportspayload-plugin-template/exports#MyComponent)// 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'
]
}
The @ alias paths map directly to your file structure:
| @ Alias | Resolves To | Export |
|---|---|---|
@components/MyComponent | dist/components/MyComponent.js or dist/components/MyComponent/index.js | Named or default export MyComponent |
@components#MyComponent | dist/components/index.js | Named export MyComponent |
@utils/helper#format | dist/utils/helper.js or dist/utils/helper/index.js | Named export format |
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'
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.
pnpm build
npm publish
pnpm add your-plugin-name
payload-pluginMIT - See LICENSE for details
Built with ❤️ using Payload CMS
Topics
payload plugin tooling
Shared lint, format, TypeScript, build, test and CI config for building Payload plugins
650/wk0v4
payload utilities
Developer helpers for Payload: document traversal, flattening, transformation and fully populated type generation
610/wk15v3
payload dev tools
Floating dev toolbar, /dev pages and an app snapshot for AI agents in Payload projects on Next.js
560/wk18v3
payload field validators
Helper functions for writing validation handlers on Payload collection fields
330/wk4v3
payload arch skill
Claude Code skill enforcing a route, controller, service and store architecture in Payload projects
322v?
plugin template
Blank starter template for building a Payload plugin in TypeScript
052v2