Skip to content

Instantly share code, notes, and snippets.

@nanxiaobei
Created September 16, 2023 20:08
Show Gist options
  • Save nanxiaobei/a3b03008b4527aeccf77c98fd17c6b0f to your computer and use it in GitHub Desktop.
Save nanxiaobei/a3b03008b4527aeccf77c98fd17c6b0f to your computer and use it in GitHub Desktop.
rollup-plugin-update
import { OutputBundle, OutputChunk, OutputOptions, Plugin } from 'rollup';
const rollupPluginUpdate = (update: (code: string) => string): Plugin => {
function generateBundle(_: OutputOptions, bundle: OutputBundle) {
for (const fileName in bundle) {
const entryFile = bundle[fileName] as OutputChunk;
if (entryFile.isEntry) {
entryFile.code = update(entryFile.code);
}
}
}
return {
name: 'update',
generateBundle,
};
};
export default rollupPluginUpdate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment