Registry / devops / webpack-preprocessor-loader

webpack-preprocessor-loader

JSON →
library1.3.0jsnpmunverified

A Webpack loader that enables conditional compilation in any text-based file. Current stable version is 1.3.0, released with support for nested if conditions, custom directives, verbose mode with escapeComments option, and builds on a rewritten codebase from v1.1.0+ that enhances multiline comment handling. It works as the last loader, processing raw text before other loaders, and supports JavaScript, HTML, CSS, and more. Unlike DefinePlugin, this loader physically removes code blocks based on directives, reducing bundle size. It requires Webpack 4+ and Node >=6.11.5.

npm install webpack-preprocessor-loader
INSTALL
IMPORT
SIG · WEBPACK-PREPROCESS
W
webpack-preprocessor-loader
devopsjavascriptv1.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 PreprocessorLoader from 'webpack-preprocessor-loader';
import { PreprocessorLoader } from 'webpack-preprocessor-loader';
This package has a default export, so named destructure will result in undefined.
resolve-loader-options
const { resolve } = require('path');
The loader is used via Webpack config, not imported directly in application code.
require-style
const PreprocessorLoader = require('webpack-preprocessor-loader');
const PreprocessorLoader = require('webpack-preprocessor-loader').default;
In CJS, the default export is the whole module.exports object, so .default is incorrect.

Webpack config and source showing conditional compilation with directives (if/else, debug, custom) using the loader's options.

// webpack.config.js module.exports = { module: { rules: [ { test: /\.js$/, use: [ 'babel-loader', { loader: 'webpack-preprocessor-loader', options: { debug: process.env.NODE_ENV !== 'production', directives: { secret: false }, params: { ENV: process.env.NODE_ENV || 'development' }, verbose: false } } ] } ] } }; // In your source file (index.js): // #!if ENV === 'production' console.log('Production build'); // #!else console.log('Development build'); // #!endif // #!debug console.log('Debug info'); // #!secret const secretKey = '12345'; // Output when NODE_ENV=production: // console.log('Production build'); // (debug block removed, secret block removed)
Debug
Known issues
gotchaDirectives must not appear inline; they must be on their own line.
fix
Place directive on its own line: // #!directive
affects: >=1.0.0
gotchaThe loader must be the last loader in the 'use' array for the rule.
fix
Put webpack-preprocessor-loader at the end of the use list, after all other loaders.
affects: >=1.0.0
gotchaThe last line of the file may be omitted if it does not end with a newline character (fixed in v1.1.1).
fix
Upgrade to v1.1.1+ or ensure files end with a newline.
affects: >=1.1.0 <=1.1.0
gotchaArray values in params may break #!if / #!elseif assertions (fixed in v1.1.4).
fix
Upgrade to v1.1.4+ or avoid arrays in params.
affects: >=1.0.0 <=1.1.3
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'webpack-preprocessor-loader'
Loader not installed or missing from package.json.
fix
npm install webpack-preprocessor-loader --save-dev
Array values in `params` break the `#!if / #!elseif` assertion
Using arrays as parameter values in params option causes type mismatch in condition evaluation.
fix
Upgrade to v1.1.4+ where arrays are handled correctly, or use scalar values.
The last line of the file will be incorrectly omitted if no new-line char presents as EOF
The loader expects newline at end of file.
fix
Upgrade to v1.1.1+ where this bug was fixed, or ensure files end with newline.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency; loader requires Webpack >=4
noderequiredruntime requirement: Node >=6.11.5 (aligned with Webpack 4)
Agent activity
12 hits · last 30 days
node
10
Resources
webpack-preprocessor-loader — npm install webpack-preprocessor-loader · libregistry