Overview
The definePlugin helper creates a TemPad Dev plugin configuration with full TypeScript type inference. It accepts a plugin configuration object and returns it with proper type annotations.
Function Signature
export function definePlugin ( plugin : Plugin ) : Plugin
Parameters
Plugin configuration object supplying metadata and code blocks. Human-readable name displayed in the UI.
Map of code block identifiers to configuration. Supports built-in blocks (css, js) and custom blocks. Each code block can be configured with: The title of the code block (e.g., ‘SCSS’, ‘Tailwind’)
The language for syntax highlighting. Options: 'text', 'tsx', 'jsx', 'ts', 'js', 'vue', 'html', 'css', 'sass', 'scss', 'less', 'stylus', 'json'
transform
(params: TransformParams) => string
transformVariable
(params: TransformVariableParams) => string
transformPx
(params: TransformPxParams) => string
transformComponent
(params: TransformComponentParams) => DevComponent | string
Returns
The same plugin configuration object, enabling type inference in user code.
Example
import { definePlugin } from '@tempad-dev/plugins'
export default definePlugin ({
name: 'My Custom Plugin' ,
code: {
css: {
title: 'CSS' ,
lang: 'css'
},
scss: {
title: 'SCSS' ,
lang: 'scss' ,
transformVariable : ({ code , name , value }) => {
// Transform CSS variables to SCSS variables
return `$ ${ name . replace ( / ^ --/ , '' ) } `
},
transformPx : ({ value , options }) => {
// Convert px to rem
if ( options . useRem ) {
return ` ${ value / options . rootFontSize } rem`
}
return ` ${ value } px`
}
},
tailwind: {
title: 'Tailwind' ,
lang: 'jsx' ,
transformComponent : ({ component }) => {
// Custom component transformation
return {
name: 'div' ,
props: { className: 'custom-class' },
children: []
}
}
}
}
})
Built-in Code Blocks
Custom Code Blocks
You can define custom code blocks by adding keys to the code object. Custom blocks inherit the same transformation capabilities as built-in blocks.
Disabling Code Blocks
Set a code block to false to disable it:
export default definePlugin ({
name: 'Minimal Plugin' ,
code: {
css: { title: 'CSS' , lang: 'css' },
js: false // Disable JS output
}
})
See Also
Transform Hooks Learn about transformation functions
Types Reference Full type definitions