Skip to content

플러그인 개발 ​

mineproj 플러그인은 훅과 컴포넌트로 빌드 파이프라인을 확장합니다.

플러그인 계약 ​

플러그인은 다음 속성을 가진 객체입니다:

속성타입필수설명
namestring✅고유 플러그인 이름
hooksRecord<string, Function>선택라이프사이클 훅 핸들러
viteVitePlugin[]선택주입할 Vite 플러그인
componentsRecord<string, Component>선택등록할 컴포넌트
optionsSchemaZodSchema선택플러그인 옵션을 위한 스키마
setupFunction선택설치 시점 훅

예제 ​

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

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

라이프사이클 훅 ​

훅타입시그니처호출 시점
config:resolvedwaterfall(config, ctx) => config설정 로드 후
data:loadedseq(_, ctx) => void데이터셋 로드 후
data:validatedseq(_, ctx) => void데이터 검증 후
routes:collectwaterfall(routes, ctx) => routes경로 수집 후
api:endpointswaterfall(endpoints, ctx) => endpointsAPI 생성 전
render:beforewaterfall(html, ctx) => html각 페이지 렌더링 전
emitseq(_, ctx) => void모든 파일 작성 후
build:doneseq(_, ctx) => void빌드 완료 후

옵션이 있는 플러그인 ​

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) => {
      // </head> 전에 분석 스니펫 삽입
      return html.replace('</head>', `${snippet}\n</head>`);
    },
  },
});

플러그인 사용하기 ​

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

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

계약 테스트 ​

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

게시 ​

  1. 패키지 이름을 mineproj-plugin-* 또는 @mineproj/plugin-*로 지정하세요
  2. package.json에 "keywords": ["mineproj-plugin"]를 추가하세요
  3. runPluginContract를 실행하여 검증하세요
  4. npm에 게시하세요

Released under the Apache-2.0 License.