import MagicString from "magic-string"; import type { OutputBundle, NormalizedOutputOptions } from "rollup"; import { composeSourcemap } from "../utils/compose-sourcemap"; export const header = (headerValue: string) => ({ name: "header", generateBundle: { order: "pre" as const, handler(_options: NormalizedOutputOptions, bundle: OutputBundle) { for (const chunk of Object.values(bundle)) { if (chunk.type !== "chunk") continue; const s = new MagicString(chunk.code!); s.prepend(headerValue); chunk.code = s.toString(); const newMap = s.generateMap({ includeContent: true, hires: true }); composeSourcemap(chunk, newMap, bundle); } }, }, });