Registry /
devops / webpack-preprocessor-loader
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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)
Errors
Common errors & fixes
Module not found: Error: Can't resolve 'webpack-preprocessor-loader'
Loader not installed or missing from package.json.
fixnpm 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.
fixUpgrade 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.
fixUpgrade to v1.1.1+ where this bug was fixed, or ensure files end with newline.
Audit
Dependencies
webpackrequiredpeer dependency; loader requires Webpack >=4
noderequiredruntime requirement: Node >=6.11.5 (aligned with Webpack 4)