{"id":20812,"library":"webpack-preprocessor","title":"webpack-preprocessor","description":"A webpack loader that strips or keeps code blocks based on preprocessor directives like `#if`, `#elif`, `#else`, `#endif`, supporting JavaScript and HTML files. It uses a declarative syntax similar to C preprocessor. Version 0.1.12 is the latest, but the project appears unmaintained (last commit years ago). Key differentiators: simple condition syntax, supports nested logic, and works with webpack 1/2 loaders. Alternatives like preprocess-loader or webpack-strip-block may be more modern.","status":"abandoned","version":"0.1.12","language":"javascript","source_language":"en","source_url":"git://git@github.com/Marc-Andre-Rivet/webpack-preprocessor","tags":["javascript","webpack","webpackloader","preprocessor"],"install":[{"cmd":"npm install webpack-preprocessor","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-preprocessor","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-preprocessor","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"runs as a webpack loader, requires webpack build system","package":"webpack","optional":false}],"imports":[{"note":"Loaders are typically referenced by name in webpack config, not imported. If imported, use default.","wrong":"const webpackPreprocessor = require('webpack-preprocessor'); // works in CommonJS, but loader config uses string","symbol":"default","correct":"import webpackPreprocessor from 'webpack-preprocessor'; // as webpack loader rule"},{"note":"This is a legacy loader for webpack 1-4. In webpack 5, use 'use' array with string.","wrong":"{ test: /\\.js$/, use: ['webpack-preprocessor'] } // not a webpack loader function, use string form","symbol":"loader","correct":"{ test: /\\.js$/, loader: 'webpack-preprocessor' }"},{"note":"Options are passed as query string. For complex values, use JSON.stringify.","wrong":"loader: 'webpack-preprocessor?definitions=dev,stage' // must be JSON array string","symbol":"query options","correct":"loader: 'webpack-preprocessor?definitions=[\"dev\",\"stage\"]'"}],"quickstart":{"code":"// webpack.config.js\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.js$/,\n        exclude: /node_modules/,\n        use: [\n          { loader: 'webpack-preprocessor', options: { definitions: ['dev'] } }\n        ]\n      }\n    ]\n  }\n};\n// In source:\n/*#if dev*/\nconsole.log('development build');\n/*#endif*/\n","lang":"javascript","description":"Set up webpack loader config and use preprocessor directives in JS files to conditionally include code based on definitions."},"warnings":[{"fix":"Use a modern loader like preprocess-loader or write inline loaders.","message":"webpack-preprocessor uses legacy webpack loader API (v1/v2), not compatible with webpack 5 pipeline.","severity":"deprecated","affected_versions":">=0.1.12"},{"fix":"Use nested conditions or chain multiple #if directives.","message":"Complex condition expressions with both && and || operators are not supported; only simple conjunctions or disjunctions work.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pass definitions as valid JSON array: definitions='[\"dev\",\"stage\"]'","message":"The loader expects definitions as a JSON array string. Non-serialized string will cause runtime errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider migrating to an actively maintained alternative.","message":"No updates since 2015; project is effectively abandoned.","severity":"deprecated","affected_versions":">=0.1.12"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install webpack-preprocessor --save-dev`.","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'webpack-preprocessor'"},{"fix":"Use `?definitions='[\"dev\"]'` or use options object with webpack 4+.","cause":"The query string options are not properly JSON-encoded.","error":"Module build failed: Error: 'definitions' must be a valid JSON array"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}