esbuild-plugin-replace
Replace strings in files while bundling
Last updated 4 years ago by naeco .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install esbuild-plugin-replace 
SYNC missed versions from official npm registry.

esbuild-plugin-replace

An esbuild plugin for replacing strings in files while bundling.

Based on @rollup/plugin-replace

CI npm license

Documentation | GitHub

Install

npm install esbuild-plugin-replace --save-dev

Quick Start

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"),
    }),
  ],
});

Options

Replacement Values

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()),
});

Filtering

  • include - RegExp to match files to process (default: /.*/)
  • exclude - RegExp to match files to skip
replace({
  include: /\.js$/,
  exclude: /node_modules/,
  values: { __VERSION__: '"1.0.0"' },
});

Delimiters

Custom delimiters for matching (default: word boundaries \b):

replace({
  delimiters: ["", ""],
  "@/src/": "./src/",
});

TypeScript

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);

License

MIT

Current Tags

  • 2.0.0                                ...           latest (3 months ago)

15 Versions

  • 2.0.0                                ...           3 months ago
  • 1.4.0                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.9                                ...           5 years ago
  • 1.0.8                                ...           5 years ago
  • 1.0.7                                ...           5 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Total 54
Today 0
This Week 2
This Month 41
Last Day 0
Last Week 25
Last Month 13
Dependencies (1)
Dev Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE