import type { Plugin } from "rollup"; import { getSwc } from "./loadSwc"; type MinifyOptions = { compress?: boolean; mangle?: boolean; }; export function minify(input: MinifyOptions = {}): Plugin { const defaults: MinifyOptions = { compress: true, mangle: true, }; const options = Object.assign( { ...defaults, }, input, ); return { name: "swc-minify", async renderChunk( contents, _, { format, sourcemap, sourcemapExcludeSources }, ) { const { minify: minifySwc } = await getSwc(); const { code, map } = await minifySwc(contents, { ...options, module: format === "es", sourceMap: !!sourcemap, inlineSourcesContent: !sourcemapExcludeSources, }); return { code, map: map || null }; }, }; }