Simple esbuild plugin for replacing file content while bundling.
npm i esbuild-plugin-replace-regex --save-dev
const replacePlugin = require('esbuild-plugin-replace-regex');
...
plugins: [
replacePlugin({
filter: /myfile/,
patterns: [
['VERSION', 'v7.7.7'],
[/myfunc\((.+?)\)/g, (m, arg) => `replaced(123, ${arg})`],
]
})
]
...
{
filter = /.*/,
loader = "tsx",
encoding = "utf-8",
patterns = []
}