{"id":25288,"library":"esbuild-ifdef","title":"esbuild-ifdef","description":"An esbuild plugin for compile-time conditional code inclusion/exclusion using `/// #if` comments. Current stable version: 0.2.0. Actively maintained, with a small feature set focused on preprocessor-like behavior. Key differentiators: uses triple-slash comments familiar from C/C++ preprocessors, supports nested conditionals, warnings/errors at compile time, and custom variable injection. Unlike alternatives that rely on other bundlers or complex setups, esbuild-ifdef integrates natively with esbuild and supports any JavaScript expression.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/zziger/esbuild-ifdef","tags":["javascript"],"install":[{"cmd":"npm install esbuild-ifdef","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-ifdef","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-ifdef","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin runs inside esbuild's build process.","package":"esbuild","optional":false}],"imports":[{"note":"Package is ESM-only; named export.","wrong":"const ifdefPlugin = require('esbuild-ifdef')","symbol":"ifdefPlugin","correct":"import { ifdefPlugin } from 'esbuild-ifdef'"},{"note":"Dynamic import for CommonJS modules.","wrong":"const ifdefPlugin = require('esbuild-ifdef')","symbol":"ifdefPlugin","correct":"const { ifdefPlugin } = await import('esbuild-ifdef')"},{"note":"TypeScript types available; options interface is also exported.","wrong":"","symbol":"ifdefPlugin (TypeScript)","correct":"import { ifdefPlugin, IfdefPluginOptions } from 'esbuild-ifdef'"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport { ifdefPlugin } from 'esbuild-ifdef';\n\nawait esbuild.build({\n  entryPoints: ['./src/index.js'],\n  bundle: true,\n  outfile: './dist/bundle.js',\n  plugins: [\n    ifdefPlugin({\n      variables: { DEBUG: true },\n    }),\n  ],\n});","lang":"typescript","description":"Demonstrates basic usage: building with esbuild and conditionally including/excluding code via the if defined plugin."},"warnings":[{"fix":"Use esbuild version matching ^0.15.2.","message":"Requires esbuild ^0.15.2; incompatible with earlier or much later versions? Check peer dependency.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Set `filePath` option to a custom RegExp to include additional file types.","message":"Default file matching regex is /\\.[jt]sx?$/, which may exclude files with unknown extensions.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Leave as true for clarity.","message":"If `requireTripleSlash` is false, double-slash comments like // #if may also be processed, but they could conflict with other syntax.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Avoid custom regex unless you understand the default pattern.","message":"The `regExp` option overrides `requireTripleSlash`; using it incorrectly may break parsing.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install esbuild-ifdef` or `yarn add esbuild-ifdef`.","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'esbuild-ifdef'"},{"fix":"Use `import { ifdefPlugin } from 'esbuild-ifdef'`.","cause":"Wrong import style; attempting to use default import instead of named export.","error":"ifdefPlugin is not a function"},{"fix":"Ensure options object has a `variables` property (e.g., `{ variables: { MY_VAR: 'value' } }`).","cause":"Passing invalid options or missing required `variables` object.","error":"The plugin \"ifdefPlugin\" failed to initialize: ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}