import type * as esbuild from 'esbuild' ; import fs from 'fs' ; function applyReplacements ( contents , replacements ) { for ( const [ regex , replacement ] of replacements ) { contents = contents . replace ( regex , replacement ) ; } return contents ; } param replacements returns export const replaceWithPlugin = ( replacements ) : esbuild . Plugin => { return { name : 'replaceWithPlugin' , setup ( build ) { build . onLoad ( { filter : /.*/ } , async ( args ) => { const contents = await fs . promises . readFile ( args . path , 'utf8' ) ; return { contents : applyReplacements ( contents , replacements ) } ; } ) ; } , } ; } ;