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

esbuild-ifdef-next

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-ifdef-next

This is fork of the [esbuild-ifdef](https://github.com/zziger/esbuild-ifdef) plugin with the latest version of esbuild. This esbuild plugin allows you to include/exclude code from your bundle conditionally on compile time using `/// #if` comments.

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

esbuild-ifdef-next

This is fork of the esbuild-ifdef plugin with the latest version of esbuild. This esbuild plugin allows you to include/exclude code from your bundle conditionally on compile time using /// #if comments.

Installation

# npm
npm install esbuild-ifdef-next

Usage

Example:

/// #if NODE_ENV === "production"
console.log('production specific code');
/// #elif NODE_ENV === "debug"
console.log('debug specific code');
/// #else
/// #warning Unknown NODE_ENV
console.log('something else');
/// #endif

All directives accept any valid javascript expressions. If blocks can be nested.

Available comments

  • /// #if expression
  • /// #elseif expression, /// #elif expression
  • /// #else
  • /// #endif
  • /// #warning text, /// #warn text - shows up a warning at compile time
  • /// #error text, /// #err text - throws an error at compile time

Using plugin

esbuild.build({
  entryPoints: ['./index.js'],
  bundle: true,
  target: 'es6',
  outfile: './out.js',
  plugins: [
    ifdefPlugin({
      variables: {
        VARIABLE_NAME: 'variable value',
      },
      // ... plugin config
    }),
  ],
});

Configuration

NameTypeDefaultDescription
verbosebooleanfalseEnabled logging of the included strings and expression results
fillWithSpacesbooleanfalseFill removed lines with spaces instead of commenting out
requireTripleSlashbooleantrueRequire usage of /// before directives
filePathRegExp/\.[jt]sx?/File matching RegExp.
regExpRegExp-Custom parsing RegExp. Overrides requireTripleSlash option. RegExp should have one group named token and one group named expression. Default RegExp for parsing triple slash directives is /\/\/\/[\s]*#(?<token>.*?)(?:[\s]+(?<expression>.*?))?[\s]*$/
variablesRecord<string, any>process.envVariables for the expressions

License

MIT

FAQs

Package last updated on 29 Nov 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