KC's Workspace
    Preparing search index...
    interface FunctionPluginHooks {
        augmentChunkHash: (
            this: PluginContext,
            chunk: RenderedChunk,
        ) => string | void;
        buildEnd: (this: PluginContext, err?: Error) => void;
        buildStart: (this: PluginContext, options: NormalizedInputOptions) => void;
        closeBundle: (this: PluginContext, error?: Error) => void;
        closeWatcher: (this: PluginContext) => void;
        generateBundle: (
            this: PluginContext,
            outputOptions: NormalizedOutputOptions,
            bundle: OutputBundle,
            isWrite: boolean,
        ) => void;
        load: (
            this: PluginContext,
            id: string,
        ) => MaybePromise<undefined | null | string | void | SourceDescription>;
        moduleParsed: (this: PluginContext, moduleInfo: ModuleInfo) => void;
        onLog: (
            this: MinimalPluginContext,
            level: "warn" | "info" | "debug",
            log: RolldownLog,
        ) => boolean | undefined | null | void;
        options: (
            this: MinimalPluginContext,
            options: InputOptions,
        ) => InputOptions | undefined | null | void;
        outputOptions: (
            this: MinimalPluginContext,
            options: OutputOptions,
        ) => OutputOptions | undefined | null | void;
        renderChunk: (
            this: PluginContext,
            code: string,
            chunk: RenderedChunk,
            outputOptions: NormalizedOutputOptions,
            meta: RenderedChunkMeta,
        ) =>
            | string
            | undefined
            | null
            | void
            | RolldownMagicString
            | { code: string | RolldownMagicString; map?: SourceMapInput | undefined };
        renderError: (this: PluginContext, error: Error) => void;
        renderStart: (
            this: PluginContext,
            outputOptions: NormalizedOutputOptions,
            inputOptions: NormalizedInputOptions,
        ) => void;
        resolveDynamicImport: (
            this: PluginContext,
            source: string,
            importer: string | undefined,
        ) => undefined | null | string | false | void | PartialResolvedId;
        resolveId: (
            this: PluginContext,
            source: string,
            importer: string | undefined,
            extraOptions: {
                custom?: CustomPluginOptions;
                isEntry: boolean;
                kind:
                    | "import-statement"
                    | "dynamic-import"
                    | "require-call"
                    | "import-rule"
                    | "url-token"
                    | "new-url"
                    | "hot-accept";
            },
        ) => undefined
        | null
        | string
        | false
        | void
        | PartialResolvedId;
        transform: (
            this: TransformPluginContext,
            code: string,
            id: string,
            meta: BindingTransformHookExtraArgs & {
                ast?: Program;
                magicString?: RolldownMagicString;
                moduleType: ModuleType;
            },
        ) => | undefined
        | null
        | string
        | void
        | Omit<SourceDescription, "code"> & { code?: string | RolldownMagicString };
        watchChange: (
            this: PluginContext,
            id: string,
            event: { event: ChangeEvent },
        ) => void;
        writeBundle: (
            this: PluginContext,
            outputOptions: NormalizedOutputOptions,
            bundle: OutputBundle,
        ) => void;
    }
    Index

    Build Hooks

    buildEnd: (this: PluginContext, err?: Error) => void

    Called when Rolldown has finished bundling, but before Output Generation Hooks. If an error occurred during the build, it is passed on to this hook.

    buildStart: (this: PluginContext, options: NormalizedInputOptions) => void

    Called on each rolldown | rolldown() build.

    This is the recommended hook to use when you need access to the options passed to rolldown | rolldown() as it takes the transformations by all options hooks into account and also contains the right default values for unset options.

    closeWatcher: (this: PluginContext) => void

    Notifies a plugin when the watcher process will close so that all open resources can be closed too.

    This hook cannot be used by output plugins.

    load: (
        this: PluginContext,
        id: string,
    ) => MaybePromise<undefined | null | string | void | SourceDescription>

    Defines a custom loader.

    Returning null defers to other load hooks or the built-in loading mechanism.

    You can use this.getModuleInfo() to find out the previous values of meta, moduleSideEffects inside this hook.

    moduleParsed: (this: PluginContext, moduleInfo: ModuleInfo) => void

    This hook is called each time a module has been fully parsed by Rolldown.

    This hook will wait until all imports are resolved so that the information in moduleInfo.importedIds, moduleInfo.dynamicallyImportedIds are complete and accurate. Note however that information about importing modules may be incomplete as additional importers could be discovered later. If you need this information, use the buildEnd hook.

    onLog: (
        this: MinimalPluginContext,
        level: "warn" | "info" | "debug",
        log: RolldownLog,
    ) => boolean | undefined | null | void

    A function that receives and filters logs and warnings generated by Rolldown and plugins before they are passed to the onLog option or printed to the console.

    If false is returned, the log will be filtered out. Otherwise, the log will be handed to the onLog hook of the next plugin, the onLog option, or printed to the console. Plugins can also change the log level of a log or turn a log into an error by passing the log object to this.error, this.warn, this.info or this.debug and returning false.

    options: (
        this: MinimalPluginContext,
        options: InputOptions,
    ) => InputOptions | undefined | null | void

    Replaces or manipulates the options object passed to rolldown | rolldown().

    Returning null does not replace anything.

    If you just need to read the options, it is recommended to use the buildStart hook as that hook has access to the options after the transformations from all options hooks have been taken into account.

    outputOptions: (
        this: MinimalPluginContext,
        options: OutputOptions,
    ) => OutputOptions | undefined | null | void

    Replaces or manipulates the output options object passed to RolldownBuild.generate | bundle.generate() or RolldownBuild.write | bundle.write().

    Returning null does not replace anything.

    If you just need to read the output options, it is recommended to use the renderStart hook as this hook has access to the output options after the transformations from all outputOptions hooks have been taken into account.

    resolveDynamicImport: (
        this: PluginContext,
        source: string,
        importer: string | undefined,
    ) => undefined | null | string | false | void | PartialResolvedId

    Defines a custom resolver for dynamic imports.

    This hook exists only for Rollup compatibility. Please use resolveId instead.

    resolveId: (
        this: PluginContext,
        source: string,
        importer: string | undefined,
        extraOptions: {
            custom?: CustomPluginOptions;
            isEntry: boolean;
            kind:
                | "import-statement"
                | "dynamic-import"
                | "require-call"
                | "import-rule"
                | "url-token"
                | "new-url"
                | "hot-accept";
        },
    ) => undefined
    | null
    | string
    | false
    | void
    | PartialResolvedId

    Defines a custom resolver.

    A resolver can be useful for e.g. locating third-party dependencies.

    Returning null defers to other resolveId hooks and eventually the default resolution behavior. Returning false signals that source should be treated as an external module and not included in the bundle. If this happens for a relative import, the id will be renormalized the same way as when the InputOptions.external option is used. If you return an object, then it is possible to resolve an import to a different id while excluding it from the bundle at the same time.

    Note that while resolveId will be called for each import of a module and can therefore resolve to the same id many times, values for external, meta or moduleSideEffects can only be set once before the module is loaded. The reason is that after this call, Rolldown will continue with the load and transform hooks for that module that may override these values and should take precedence if they do so.

    transform: (
        this: TransformPluginContext,
        code: string,
        id: string,
        meta: BindingTransformHookExtraArgs & {
            ast?: Program;
            magicString?: RolldownMagicString;
            moduleType: ModuleType;
        },
    ) => | undefined
    | null
    | string
    | void
    | Omit<SourceDescription, "code"> & { code?: string | RolldownMagicString }

    Can be used to transform individual modules.

    Note that it's possible to return only properties and no code transformations.

    You can use this.getModuleInfo() to find out the previous values of meta, moduleSideEffects inside this hook.

    watchChange: (
        this: PluginContext,
        id: string,
        event: { event: ChangeEvent },
    ) => void

    Notifies a plugin whenever Rolldown has detected a change to a monitored file in watch mode.

    If a build is currently running, this hook is called once the build finished. It will be called once for every file that changed.

    This hook cannot be used by output plugins.

    If you need to be notified immediately when a file changed, you can use the watch.onInvalidate option.

    Output Generation Hooks

    augmentChunkHash: (this: PluginContext, chunk: RenderedChunk) => string | void

    Can be used to augment the hash of individual chunks. Called for each Rolldown output chunk.

    Returning a falsy value will not modify the hash. Truthy values will be used as an additional source for hash calculation.

    closeBundle: (this: PluginContext, error?: Error) => void

    Can be used to clean up any external service that may be running.

    Rolldown's CLI will make sure this hook is called after each run, but it is the responsibility of users of the JavaScript API to manually call RolldownBuild.close | bundle.close() once they are done generating bundles. For that reason, any plugin relying on this feature should carefully mention this in its documentation.

    If a plugin wants to retain resources across builds in watch mode, they can check for PluginContextMeta.watchMode | this.meta.watchMode in this hook and perform the necessary cleanup for watch mode in closeWatcher.

    generateBundle: (
        this: PluginContext,
        outputOptions: NormalizedOutputOptions,
        bundle: OutputBundle,
        isWrite: boolean,
    ) => void

    Called at the end of RolldownBuild.generate | bundle.generate() or immediately before the files are written in RolldownBuild.write | bundle.write().

    To modify the files after they have been written, use the writeBundle hook.

    renderChunk: (
        this: PluginContext,
        code: string,
        chunk: RenderedChunk,
        outputOptions: NormalizedOutputOptions,
        meta: RenderedChunkMeta,
    ) =>
        | string
        | undefined
        | null
        | void
        | RolldownMagicString
        | { code: string | RolldownMagicString; map?: SourceMapInput | undefined }

    Can be used to transform individual chunks. Called for each Rolldown output chunk file.

    Returning null will apply no transformations. If you change code in this hook and want to support source maps, you need to return a map describing your changes, see Source Code Transformations section.

    chunk is mutable and changes applied in this hook will propagate to other plugins and to the generated bundle. That means if you add or remove imports or exports in this hook, you should update RenderedChunk.imports | imports, RenderedChunk.importedBindings | importedBindings and/or RenderedChunk.exports | exports accordingly.

    renderError: (this: PluginContext, error: Error) => void

    Called when Rolldown encounters an error during RolldownBuild.generate | bundle.generate() or RolldownBuild.write | bundle.write().

    To get notified when generation completes successfully, use the generateBundle hook.

    renderStart: (
        this: PluginContext,
        outputOptions: NormalizedOutputOptions,
        inputOptions: NormalizedInputOptions,
    ) => void

    Called initially each time RolldownBuild.generate | bundle.generate() or RolldownBuild.write | bundle.write() is called.

    To get notified when generation has completed, use the generateBundle and renderError hooks.

    This is the recommended hook to use when you need access to the output options passed to RolldownBuild.generate | bundle.generate() or RolldownBuild.write | bundle.write() as it takes the transformations by all outputOptions hooks into account and also contains the right default values for unset options.

    It also receives the input options passed to rolldown | rolldown() so that plugins that can be used as output plugins, i.e. plugins that only use generate phase hooks, can get access to them.

    writeBundle: (
        this: PluginContext,
        outputOptions: NormalizedOutputOptions,
        bundle: OutputBundle,
    ) => void

    Called only at the end of RolldownBuild.write | bundle.write() once all files have been written.