Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-plugin-replace

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-plugin-replace

Replace strings in files while bundling

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

esbuild-plugin-replace

🚀 A Esbuild plugin which replaces targeted strings in files while bundling

This package is based on @rollup/plugin-replace

Install

using npm:

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

using yarn:

yarn add esbuild-plugin-replace -D

Usage

const { build } = require('esbuild');
const { replace } = require('esbuild-plugin-replace');
build({
  // other build options
  plugins: [
    replace({
        '__buildVersion': '"1.0.0"',
        '__author__': `'naecoo'`
    })
  ]
});

The configuration above will replace every instance of __buildVersion with "1.0.0" and __author with 'naecoo'

Note: Values must be either primitives (e.g. string, number) or function that returns a string. For complex values, use JSON.stringify. To replace a target with a value that will be evaluated as a string, set the value to a quoted string (e.g. "test") or use JSON.stringify to preprocess the target string safely.

Options

In addition to the properties and values specified for replacement, users may also specify the options below.

include

Type: RegExp

default: /.*/

Filters files that do not match RegExp expressions. By default all files are matched.

exclude

Type: RegExp

default: null

Filters files that do match the exclude RegExp expressions. When include and exclude are set at the same time, include is used first, and exclude doesn't work.

values

Type: { [key: String]: Replacement }, where Replacement is either a string or a function that returns a string.

Default: {}

To avoid mixing replacement strings with the other options, you can specify replacements in the values option. For example, the following signature:

replace({
  include: /\.js$/,
  changed: "replaced"
});

Can be replaced with:

replace({
  include: /\.js$/,
  values: {
    changed: "replaced"
  }
});

delimiters

Type: Array[String, String]

Default: ['\b', '\b']

Specifies the boundaries around which strings will be replaced. By default, delimiters are word boundaries. See Word Boundaries below for more information.

Keywords

FAQs

Package last updated on 23 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc