$ npm install esbuild-plugin-replace
An esbuild plugin for replacing strings in files while bundling.
Based on @rollup/plugin-replace
npm install esbuild-plugin-replace --save-dev
import { build } from "esbuild";
import { replace } from "esbuild-plugin-replace";
await build({
entryPoints: ["src/index.js"],
bundle: true,
plugins: [
replace({
__VERSION__: JSON.stringify("1.0.0"),
__AUTHOR__: JSON.stringify("naecoo"),
}),
],
});
Specify replacements directly:
replace({
__VERSION__: JSON.stringify("1.0.0"),
});
Or use the values option:
replace({
values: {
__VERSION__: JSON.stringify("1.0.0"),
},
});
Values can also be functions:
replace({
__BUILD_TIME__: () => JSON.stringify(Date.now()),
});
include - RegExp to match files to process (default: /.*/)exclude - RegExp to match files to skipreplace({
include: /\.js$/,
exclude: /node_modules/,
values: { __VERSION__: '"1.0.0"' },
});
Custom delimiters for matching (default: word boundaries \b):
replace({
delimiters: ["", ""],
"@/src/": "./src/",
});
Full TypeScript support is included. Types are auto-generated.
import { replace, ReplaceOptions } from "esbuild-plugin-replace";
const options: ReplaceOptions = {
__VERSION__: JSON.stringify("1.0.0"),
};
replace(options);
MIT
© 2010 - cnpmjs.org x YWFE | Home | YWFE