Registry / http-networking / preprocess-loader

preprocess-loader

JSON →
library0.3.0jsnpmunverified

A webpack loader that uses the preprocess library to conditionally include or exclude code in HTML, JavaScript, CoffeeScript, and other module files based on custom or environment configurations. Version 0.3.0 is the latest stable release (the project appears inactive since 2017). It supports Webpack 1 and 2+ and allows overriding preprocess options via the `ppOptions` query parameter. Similar to gulp-preprocess, it provides directive syntax for conditional compilation (@if, @ifdef, @echo, @include). The loader is typically placed before other loaders in a chain to preprocess files before they are transpiled.

npm install preprocess-loader
INSTALL
IMPORT
SIG · PREPROCESS-LOADER
P
preprocess-loader
http-networkingjavascriptv0.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import PreprocessLoader from 'preprocess-loader'
const PreprocessLoader = require('preprocess-loader')
As a webpack loader, it is not typically imported directly; it is configured in webpack.config via loader name string 'preprocess-loader'. The import pattern is uncommon but shown for completeness.
useLoader
module.exports = { module: { rules: [ { test: /\.js$/, use: 'preprocess-loader?+DEBUG' } ] } }
module.exports = { module: { loaders: [ { test: /\.js$/, loader: 'preprocess-loader?+DEBUG' } ] } }
Webpack 2+ uses `rules` and `use` instead of `loaders`. The old `loaders` array is deprecated.
queryOptions
use: [ { loader: 'preprocess-loader', options: { DEBUG: true, NODE_ENV: 'production' } } ]
use: [ { loader: 'preprocess-loader?DEBUG=true&NODE_ENV=production' } ]
Webpack 2+ supports the `options` object. Query string may still work but is less maintainable.

Webpack 2+ configuration using preprocess-loader with environment variables and Babel.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.js$/, use: [ { loader: 'preprocess-loader', options: { DEBUG: process.env.DEBUG === 'true' ? true : false, NODE_ENV: process.env.NODE_ENV ?? 'production' } }, 'babel-loader' ] } ] } }; // In your source.js const configValue = '/* @echo FOO */' || 'default value'; // @ifdef DEBUG console.log('Debugging enabled'); // @endif
Debug
Known issues
gotchaLoader chain ordering matters: preprocess-loader should run before other loaders (e.g., babel-loader) to avoid preprocessed comments being transpiled away.
fix
Place preprocess-loader earlier in the `use` array (right-to-left execution).
affects: >=0.0.0
gotchaDirectives inside @echo blocks may not be processed in coffee/shell type unless you apply a second preprocess pass after compilation.
fix
Chain two preprocess loaders: one with type:'cjsx' before CoffeeScript loader, one with type:'js' after.
affects: >=0.0.0
deprecatedWebpack 1 style `loaders` array with query strings is deprecated in Webpack 2+.
fix
Use `rules` with `use` array and `options` object.
affects: >=2.0.0
breakingUpgrade from v0.1.0 to v0.2.0 updated preprocess from v2 to v3, which may change behavior of some directives.
fix
Check preprocess v3 release notes for breaking changes; update your code if necessary.
affects: ~0.1.0
Errors
Common errors & fixes
Cannot find module 'preprocess-loader'
Missing npm install or not installed as devDependency.
fix
Run `npm install preprocess-loader --save-dev` or `yarn add preprocess-loader --dev`.
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
Using Webpack 2+ with the old `loaders` array instead of `rules`.
fix
Replace `module.loaders` with `module.rules` and `loader` with `use`.
Module build failed: Error: You may need an appropriate loader to handle this file type.
preprocess-loader is not in the loader chain or is placed after a loader that removes comments.
fix
Add preprocess-loader to the `use` array before other loaders (e.g., before babel-loader).
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
preprocessrequiredCore dependency for text preprocessing (directives, conditionals).
webpackrequiredPeer dependency – loader operates within webpack's build system.
Agent activity
5 hits · last 30 days
node
4
Bingbot
1
Resources
preprocess-loader — npm install preprocess-loader · libregistry