webpack-remove-debug
raw JSON → 0.1.0 verified Sat Apr 25 auth: no javascript abandoned
A Webpack loader that removes all calls to the `debug` library and its associated require statements from your production code. v0.1.0, last release in 2021, no active maintenance. It specifically targets `debug(…)` function calls and `require('debug')` patterns, with no configuration parameters. Similar to strip-loader but limited to debug and only works for CommonJS require, not ES module imports. No updates or security patches since release.
Common errors
error Error: Module not found: Error: Can't resolve 'webpack-remove-debug' ↓
cause Loader not installed or missing from node_modules.
fix
Run
npm install --save-dev webpack-remove-debug. error Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type. ↓
cause Webpack expects a loader rule, but the loader might be misconfigured or order is wrong.
fix
Ensure the rule is added before other loaders (e.g., babel-loader). Example:
{ test: /\.js$/, use: [{ loader: 'webpack-remove-debug' }, { loader: 'babel-loader' }] } error debug is not defined ↓
cause The require statement was stripped but debug calls remain (maybe due to import syntax).
fix
Change
import debug from 'debug' to const debug = require('debug')('...'). Or omit loader and handle differently. Warnings
gotcha Does not strip ES module imports (`import debug from 'debug'`). Only CommonJS `require` is supported. ↓
fix Use `const debug = require('debug')('...')` instead of import, or use an alternative loader that supports ES modules.
gotcha Only removes simple `debug(...)` calls. Complex expressions like `debug && debug('msg')` or chained calls are not stripped. ↓
fix Ensure debug calls are in the form `debug('message', ...);` for removal.
gotcha If you have other code using debug variable (e.g., pass it around), the loader may break scope inadvertently. ↓
fix Use a more thorough stripping tool like strip-loader or babel-plugin-transform-remove-console for production.
Install
npm install webpack-remove-debug yarn add webpack-remove-debug pnpm add webpack-remove-debug Imports
- webpack-remove-debug (loader) wrong
import webpackRemoveDebug from 'webpack-remove-debug';correctmodule.exports = { module: { rules: [{ test: /\.js$/, loader: 'webpack-remove-debug' }] } }; - debug wrong
import debug from 'debug';correctconst debug = require('debug')('myapp'); - debug() wrong
debug?.('message');correctdebug('some message', data);
Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
loader: 'webpack-remove-debug'
}
]
}
};
// In your source code (will be stripped):
const debug = require('debug')('myapp');
debug('This will be removed in production');
// In your source code (will NOT be stripped):
import debug from 'debug';
debug('This will remain, not removed');