{"id":22065,"library":"rollup-plugin-ifdef","title":"rollup-plugin-ifdef","description":"A conditional compilation plugin for Rollup and Vite, allowing you to include or exclude code blocks based on build-time flags or environment variables. Supports JavaScript, TypeScript, CSS, SCSS, Vue, and React files. v1.1.1 is the current stable version, released in 2023 and last updated in 2023. It uses a comment-based syntax (e.g., @ifdef and @ifndef) similar to C preprocessor directives, making it easy to toggle debug code, platform-specific features, or feature flags without modifying the source. Unlike alternatives that rely on environment variable replacement or dead-code elimination, this plugin performs actual code removal at build time, ensuring zero runtime overhead.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","rollup","vite","ifdebug","conditional","compile","typescript"],"install":[{"cmd":"npm install rollup-plugin-ifdef","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-ifdef","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-ifdef","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core peer dependency; plugin is designed to work as a Rollup plugin.","package":"rollup","optional":false},{"reason":"Used for filtering files by pattern; automatically required at runtime.","package":"@rollup/pluginutils","optional":false},{"reason":"Used for source map manipulation during code transformation.","package":"magic-string","optional":false}],"imports":[{"note":"Package is ESM-only; CommonJS require() will fail with Rollup/Vite. Use import.","wrong":"const ifdef = require('rollup-plugin-ifdef')","symbol":"default","correct":"import ifdef from 'rollup-plugin-ifdef'"},{"note":"The plugin is exported as default, not a named export. Named import will be undefined.","wrong":"import { ifdef } from 'rollup-plugin-ifdef'","symbol":"ifdef","correct":"import ifdef from 'rollup-plugin-ifdef'"},{"note":"No separate Vite plugin; use the same module in vite.config.js under plugins array.","wrong":"import ifdef from 'rollup-plugin-ifdef/vite'","symbol":"ifdef (Vite)","correct":"import ifdef from 'rollup-plugin-ifdef' // in vite.config.js"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport ifdef from 'rollup-plugin-ifdef';\n\nexport default defineConfig({\n  plugins: [\n    ifdef({\n      DEBUG: process.env.NODE_ENV === 'development' ? 'true' : 'false',\n    }),\n  ],\n});\n\n// src/main.js\n// @ifdef DEBUG\nconsole.log('Debug mode');\n// @endif\n\n// @ifndef DEBUG\nconsole.log('Production mode');\n// @endif\n","lang":"javascript","description":"Shows Vite setup with environment variable DEBUG; conditionally compile code blocks based on NODE_ENV."},"warnings":[{"fix":"Always wrap boolean flags in quotes: 'true' vs 'false' (or use 'defined' check).","message":"Conditions are string comparisons; boolean values from process.env are strings, so flags must be set as strings 'true'/'false' not boolean true/false.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Place conditional code inside /* @ifdef */ comments, not inside JavaScript strings or expressions.","message":"The plugin uses comment-based syntax; it will not work with dynamic expressions or template literals. Code inside conditionals must be statically analyzable.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update comments from //#ifdef to /* @ifdef */ or use the new syntax. Refer to migration guide.","message":"Version 1.x uses a different syntax than 0.x; @ifdef/@ifndef instead of //#ifdef. Existing code from 0.x will not be recognized.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Avoid nesting; use logical operators in the condition if needed (e.g., DEBUG && FEATURE_X).","message":"Nested conditionals are not supported; having @ifdef inside another @ifdef block may lead to incorrect compilation.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2023':47,52 'actual':103 'allow':13 'altern':88 'base':21,58 'block':20 'build':24,107 'build-tim':23 'c':66 'code':19,75,98,104 'comment':57 'comment-bas':56 'compil':7,118 'condit':6,117 'css':33 'current':42 'dead':97 'dead-cod':96 'debug':74 'direct':68 'e.g':60 'easi':71 'elimin':99 'ensur':109 'environ':28,92 'exclud':18 'featur':79,81 'file':38 'flag':26,82 'ifdebug':116 'ifdef':4,61 'ifndef':63 'includ':16 'javascript':31,113 'last':49 'make':69 'modifi':84 'overhead':112 'perform':102 'platform':77 'platform-specif':76 'plugin':3,8,101 'preprocessor':67 'react':37 'releas':45 'reli':90 'remov':105 'replac':94 'rollup':2,10,114 'rollup-plugin-ifdef':1 'runtim':111 'scss':34 'similar':64 'sourc':86 'specif':78 'stabl':43 'support':30 'syntax':59 'time':25,108 'toggl':73 'typescript':32,119 'unlik':87 'updat':50 'use':54 'v1.1.1':39 'variabl':29,93 'version':44 'vite':12,115 'vue':35 'without':83 'zero':110","created_at":"2026-04-27T17:03:12.458283+00:00","updated_at":"2026-04-27T17:03:12.458283+00:00","problems":[{"fix":"Run npm install rollup-plugin-ifdef --save-dev","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'rollup-plugin-ifdef'"},{"fix":"Use default import: import ifdef from 'rollup-plugin-ifdef'","cause":"Named import instead of default import: import { ifdef } from 'rollup-plugin-ifdef'","error":"'ifdef' is not a function"},{"fix":"Ensure plugin is only included once in plugins array. If using with other plugins, set 'order' or 'enforce' to 'pre'.","cause":"Plugin is applied multiple times or incorrectly configured to process its own output.","error":"Potential infinite recursion: found plugin 'ifdef' for file '...'"},{"fix":"Use correct syntax: /* @ifdef FLAG_NAME */ or /* @ifndef FLAG_NAME */","cause":"Syntax error in comment: missing condition or invalid characters (e.g., using == instead of plain string).","error":"Error: @ifdef expected a valid condition"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/rollup-plugin-ifdef","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-18","next_check":"2026-07-26","install_tag":null}}