Webpack loader that adds conditional compilation directives (`#if`, `#elif`, `#else`, `#endif`) inside JavaScript or TypeScript comments, processed at build time. Current stable version is 2.3.2 (last released on npm), with no fixed release cadence; the project appears to be in maintenance mode with infrequent updates. Key differentiators: directives are written inside triple-slash comments so they don't interfere with normal parsing or linters; supports nested conditions, arbitrary JS expressions, and an uncomment-prefix feature to hide syntactically invalid code in comments. Comparable to `preprocessor-loader` or manual environment-based code stripping.
npm install ifdef-loaderVerified import paths — ran on the pinned version, not inferred.
Demonstrates Webpack config with ifdef-loader placed after ts-loader, enabling DEBUG variable and all supported options.
Use triple-slash comments or set `ifdef-triple-slash: false` in options.
Put ifdef-loader as the last entry in the `use` array (e.g., `use: ['ts-loader', 'ifdef-loader']`).
Use string values: `{ DEBUG: 'true' }` and compare with string: `/// #if DEBUG == 'true'`.Ensure special options always include the `ifdef-` prefix (e.g., `'ifdef-triple-slash': true`).
Either update all directives to triple-slash comments or set `ifdef-triple-slash: false` in options.
Ensure the loader is only applied to files that contain conditional compilation directives, or add a `#if` at least one block.
Use exactly 'ifdef-verbose' (with hyphen and prefix).
Ensure every `#if` has a corresponding `#endif`, and nested blocks are properly balanced.