Giter Site home page Giter Site logo

gluck / esbuild-plugin-replace Goto Github PK

View Code? Open in Web Editor NEW

This project forked from naecoo/esbuild-plugin-replace

0.0 0.0 0.0 83 KB

A Esbuild plugin which replaces targeted strings in files while bundling

License: MIT License

JavaScript 94.87% TypeScript 5.13%

esbuild-plugin-replace's Introduction

esbuild-plugin-replace

๐Ÿš€ A Esbuild plugin which replaces targeted strings in files while bundling

This packages 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.

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

Todo

  1. Support exclude and preventAssignment options
  2. Add unit test

esbuild-plugin-replace's People

Contributors

bennypowers avatar naecoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.