Created
September 16, 2023 20:08
-
-
Save nanxiaobei/a3b03008b4527aeccf77c98fd17c6b0f to your computer and use it in GitHub Desktop.
rollup-plugin-update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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