https://github.com/morganney/webpack-strip-debug-loader
Removes debug statements during your webpack builds.
https://github.com/morganney/webpack-strip-debug-loader
debug javascript loader nodejs webpack
Last synced: 5 months ago
JSON representation
Removes debug statements during your webpack builds.
- Host: GitHub
- URL: https://github.com/morganney/webpack-strip-debug-loader
- Owner: morganney
- Created: 2021-08-26T14:55:14.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-08-30T22:37:08.000Z (almost 2 years ago)
- Last Synced: 2025-08-09T19:02:43.706Z (11 months ago)
- Topics: debug, javascript, loader, nodejs, webpack
- Language: JavaScript
- Homepage:
- Size: 583 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# [`webpack-strip-debug-loader`](https://www.npmjs.com/package/webpack-strip-debug-loader)

[](https://codecov.io/gh/morganney/webpack-strip-debug-loader)
> [!WARNING]
> Uses a regex to find `debug` usage, your mileage may vary.
Removes [`debug`](https://www.npmjs.com/package/debug) usage from your source code during webpack builds.
## Usage
First `npm install webpack-strip-debug-loader debug`.
### Debugging
You must use the wrapper around [`debug`](https://www.npmjs.com/package/debug) named `Debug` that this package exposes. All debug functions must be prefixed with `debug` or they will not be removed.
Do not:
* Alias your `import` or `require` of `Debug`
* Spread your `require` of `Debug` over more than one line
Just make simple debug statements.
```js
import { Debug } from 'webpack-strip-debug-loader'
// Or use require if you prefer that
const { Debug } = require('webpack-strip-debug-loader')
const debug = Debug('feature')
const debugFoo = Debug('foo')
if (somethingOfInterestHappens) {
debug('something happened')
}
if (foo) {
debugFoo(
'foo happened',
foo,
{ ...foo }
someFunc(foo)
)
}
```
### Viewing
To see the debug statements open the dev tools panel in your browser. Then update local storage:
```js
localStorage.debug = 'some:feature'
// Or to view all debug statements
localStorage.debug = '*'
```
Now reload your browser. To turn off debugging you can `localStorage.debug = false`.
### Stripping
To remove the logging and bundling of `debug` usage register this loader with webpack.
```js
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['webpack-strip-debug-loader']
}
]
}
```