rollup-plugin-debug
Console debug statements that can be pattern toggled at compile time from comments in the code.
npm i rollup-plugin-debug
|
pnpm add rollup-plugin-debug
|
yarn add rollup-plugin-debug
|
Examples
# web
# view source
example/web.ts
export {}
//!? 'hello world'
const someVar = 123
//!warn 'warning', someVar
//!time 'time'
//!timeEnd 'time'
console.log('sink', someVar)
//!> alert('hello')
API
boolean boolean string [] boolean#
src/rollup-plugin-debug.ts#L18 RollupPluginDebugOptions
– Plugin options.
#
src/rollup-plugin-debug.ts#L22 exclude
– Exclude patterns.
null
| string | RegExp | string | RegExp []#
src/rollup-plugin-debug.ts#L20 include
– Include patterns.
null
| string | RegExp | string | RegExp []#
src/rollup-plugin-debug.ts#L30 printId
– Whether to print colored label ids. Default: true
#
src/rollup-plugin-debug.ts#L32 removeIfUnmatched
– Whether to erase the comment completely when not matched. Default: false
#
src/rollup-plugin-debug.ts#L34 removeParts
– Parts of the label namespace to remove. Default: ['lib', 'src', 'dist', 'esm', 'cjs']
#
src/rollup-plugin-debug.ts#L28 runtimeDebug
– Enable runtime localStorage.DEBUG='<regexp>'
# default
(options) – Compile time "debug" plugin for browser builds.
src/rollup-plugin-debug.ts#L91
Enables the following:
//!? 'foo', bar
//!warn 'xyz'
//!time 'bench'
//!> if (x) { ... }
// is compiled to:
console.log('foo', bar)
console.warn('xyz')
console.time('bench')
if (x) { ... }
Along with colored label ids namespaced to the package name + filename
(excluding specific common parts like src
or lib
or dist
, configurable).
To enable a namespace, or all it is using the same pattern matching as the debug
package:
ROLLUP_DEBUG='some-module:*,other:*,-notthis*' npm run build
Will enable the logs just for these modules. The main difference from the debug
package,
aside from being compile time rather than runtime, is that in DevTools you get the proper
file/line link as the call sites of console.*
are in the right place, instead of being
one module deep, which would point you to debug.js
which was not helpful.
# options
= {}
– RollupPluginDebugOptions
default(options) =>
- Plugin
Credits
- debug by Josh Junon – Lightweight debugging utility for Node.js and the browser
- everyday-utils by stagas – Everyday utilities
- magic-string by Rich Harris – Modify strings, generate sourcemaps
- new-find-package-json by hasezoey – Find the an package.json in the path provided upwards
- rollup-pluginutils by Rich Harris – Functionality commonly needed by Rollup plugins
- source-map by Nick Fitzgerald – Generates and consumes source maps
Contributing
All contributions are welcome!