rollup-plugin-debug
v0.2.0
Published
Console debug statements that can be pattern toggled at compile time from comments in the code.
Downloads
31
Readme
Console debug statements that can be pattern toggled at compile time from comments in the code.
Examples
export {}
//!? 'hello world'
const someVar = 123
//!warn 'warning', someVar
//!time 'time'
//!timeEnd 'time'
console.log('sink', someVar)
//!> alert('hello')
API
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.
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!
License
MIT © 2022 stagas