webpack-strip-debug-loader

1.3.4 • Public • Published

webpack-strip-debug-loader

CI codecov

[!WARNING] Uses a regex to find debug usage, your mileage may vary.

Removes 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 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.

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:

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.

module: {
  rules: [
    {
        test: /\.js$/,
        exclude: /node_modules/,
        use: ['webpack-strip-debug-loader']
    }
  ]
}

Package Sidebar

Install

npm i webpack-strip-debug-loader

Weekly Downloads

15

Version

1.3.4

License

MIT

Unpacked Size

3.36 kB

Total Files

2

Last publish

Collaborators

  • morganney