Rocket Logo Rocket Guides Docs Blog Toggle darkmode

Create your Own: Hooks

Your preset can hook into the rocket lifecycle by specifying a function for before11ty. This function runs before 11ty calls it's write method. If it is an async function, Rocket will await it's promise.

/** @type {import('@rocket/cli').RocketPreset} */
export default ({
  async before11ty() {
    await copyDataFiles();
  },
});

Preset Interface

The full preset interface is copied below for your reference.

import { AddPluginFn } from 'plugins-manager';

type ImageFormat = 'avif' | 'webp' | 'jpg' | 'jpeg' | 'png' | 'svg';

export interface ImagePreset {
  widths: number[];
  formats: ImageFormat[];
  sizes: string;
}

type ImagePresetHook = (preset: { [key: string]: ImagePreset }) => { [key: string]: ImagePreset };

export interface RocketPreset {
  path: string;

  adjustImagePresets?: ImagePresetHook;

  /** Hook that runs before rocket starts 11ty. Can be sync or async */
  before11ty?: () => void | Promise<void>;

  // TODO: improve all setup functions
  setupUnifiedPlugins?: AddPluginFn[];
  setupDevAndBuildPlugins?: AddPluginFn[];
  setupBuildPlugins?: AddPluginFn[];
  setupDevPlugins?: AddPluginFn[];
  setupCliPlugins?: AddPluginFn[];
  setupEleventyPlugins?: AddPluginFn[];
  setupEleventyComputedConfig?: AddPluginFn[];
}