项目作者: morganney

项目描述 :
Removes debug statements during your webpack builds
高级语言: JavaScript
项目地址: git://github.com/morganney/webpack-strip-debug-loader.git
创建时间: 2021-08-26T14:55:14Z
项目社区:https://github.com/morganney/webpack-strip-debug-loader

开源协议:

下载


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.

  1. import { Debug } from 'webpack-strip-debug-loader'
  2. // Or use require if you prefer that
  3. const { Debug } = require('webpack-strip-debug-loader')
  4. const debug = Debug('feature')
  5. const debugFoo = Debug('foo')
  6. if (somethingOfInterestHappens) {
  7. debug('something happened')
  8. }
  9. if (foo) {
  10. debugFoo(
  11. 'foo happened',
  12. foo,
  13. { ...foo }
  14. someFunc(foo)
  15. )
  16. }

Viewing

To see the debug statements open the dev tools panel in your browser. Then update local storage:

  1. localStorage.debug = 'some:feature'
  2. // Or to view all debug statements
  3. 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.

  1. module: {
  2. rules: [
  3. {
  4. test: /\.js$/,
  5. exclude: /node_modules/,
  6. use: ['webpack-strip-debug-loader']
  7. }
  8. ]
  9. }