Skip to content

Plugin Development ​

mineproj plugins extend the build pipeline with hooks and components.

Plugin Contract ​

A plugin is an object with:

PropertyTypeRequiredDescription
namestring✅Unique plugin name
hooksRecord<string, Function>OptionalLifecycle hook handlers
viteVitePlugin[]OptionalVite plugins to inject
componentsRecord<string, Component>OptionalComponents to register
optionsSchemaZodSchemaOptionalSchema for plugin options
setupFunctionOptionalInstall-time hook

Example ​

ts
import { definePlugin } from '@mineproj/core';

export default definePlugin({
  name: 'mineproj-plugin-hello',
  hooks: {
    'build:done': () => {
      console.log('Build complete!');
    },
  },
});

Lifecycle Hooks ​

HookTypeSignatureCalled When
config:resolvedwaterfall(config, ctx) => configAfter config is loaded
data:loadedseq(_, ctx) => voidAfter dataset loads
data:validatedseq(_, ctx) => voidAfter data validation
routes:collectwaterfall(routes, ctx) => routesAfter routes are collected
api:endpointswaterfall(endpoints, ctx) => endpointsBefore API emission
render:beforewaterfall(html, ctx) => htmlBefore each page render
emitseq(_, ctx) => voidAfter all files are written
build:doneseq(_, ctx) => voidAfter build completes

Plugin with Options ​

ts
import { z } from 'zod';
import { definePlugin } from '@mineproj/core';

export default definePlugin({
  name: '@mineproj/plugin-analytics',
  optionsSchema: z.object({
    provider: z.enum(['umami', 'plausible', 'ga']),
    id: z.string(),
  }),
  hooks: {
    'render:before': (html, ctx) => {
      // Inject analytics snippet before </head>
      return html.replace('</head>', `${snippet}\n</head>`);
    },
  },
});

Using a Plugin ​

ts
// mineproj.config.ts
import { defineSeoPlugin } from '@mineproj/plugin-seo';

export default defineConfig({
  plugins: [
    defineSeoPlugin({ siteUrl: 'https://example.com', siteTitle: 'My Site' }),
  ],
});

Contract Testing ​

ts
import { runPluginContract } from '@mineproj/test-utils';
const result = runPluginContract(myPlugin);
console.log(result.errors); // [] if valid

Publishing ​

  1. Name your package mineproj-plugin-* or @mineproj/plugin-*
  2. Add "keywords": ["mineproj-plugin"] to package.json
  3. Run runPluginContract to validate
  4. Publish to npm

Released under the Apache-2.0 License.