A Babel plugin that performs conditional compilation by evaluating if statements with predefined constants and removing dead code. Version 0.0.5 is the latest stable release, updated infrequently (last release in 2016). It allows developers to define compile-time constants (e.g., IS_DEV, CODE_FOR_IE) and automatically eliminate unreachable branches during bundling, reducing bundle size. Unlike webpack's DefinePlugin or similar tools, this operates at the AST level within Babel transformation pipeline. Supports dropping debugger statements and arbitrary constant replacement. Lacks TypeScript definitions and ES module support; designed for legacy Babel 6.x.
npm install babel-plugin-conditional-compileVerified import paths — ran on the pinned version, not inferred.
Demonstrates using Babel 6 with the plugin to remove dead code based on compile-time constants. Sets IS_DEV to false and CODE_FOR_CHROME to true, removing the IE branch and debug log.
Use @babel/plugin-transform-conditional-compile or other modern alternatives.
Ensure your Babel preset is set to transform ES modules to CommonJS, or use a different plugin that supports ESM.
Do not attempt to require the plugin yourself. Instead, specify it in .babelrc or babel.transform plugins array as a string.
Always pass an object with define property, even if empty: plugins: [['conditional-compile', {}]]Install 'babel-core' (legacy): npm install babel-core@6 --save-dev, or migrate to a plugin compatible with @babel/core.
Ensure the plugin is listed in .babelrc. Example: { plugins: [['conditional-compile', { define: { IS_DEV: true } }]] }Reference the plugin by its package name string in the plugins array: ['conditional-compile', options]