{"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,"search_vec":"'0.1.12':37 '1/2':62 'ago':49 'altern':64 'appear':44 'base':13 'block':12,73 'c':34 'code':11 'commit':47 'condit':53 'declar':30 'differenti':51 'direct':16 'elif':19 'els':20 'endif':21 'file':26 'html':25 'javascript':23,78 'keep':10 'key':50 'last':46 'latest':40 'like':17,65 'loader':6,63,68 'logic':57 'may':74 'modern':77 'nest':56 'preprocess':67 'preprocess-load':66 'preprocessor':3,15,35,81 'project':43 'similar':32 'simpl':52 'strip':8,72 'support':22,55 'syntax':31,54 'unmaintain':45 'use':28 'version':36 'webpack':2,5,61,71,79 'webpack-preprocessor':1 'webpack-strip-block':70 'webpackload':80 'work':59 'year':48","created_at":"2026-04-25T11:25:06.343598+00:00","updated_at":"2026-04-25T11:25:06.343598+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Marc-Andre-Rivet/webpack-preprocessor","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/webpack-preprocessor","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-17","next_check":"2026-07-24","install_tag":null}}