I'd like to wrap my code in a custom type of Closure during build process with Grunt (and uglify). This manipulation must keep the sourceMap working.
My use case is to wrap all my code inside a try/catch
block to allow logging of the errors in production - without losing access to the stacktrace (unlike window.onerror
). I'd probably use Raven-js 1.0 to work this out.
Anyone know how I could manage this easily?
If you just have tips that might bring a full answer, that'll be accepted too
Finally, I've found a grunt plugin (grunt-wrap) who does exactly this:
wrap: {
modules: {
src: ['assets/*.js'],
dest: 'dist/',
wrapper: ['try {', '} catch(e) { Raven.captureException(e); }']
}
}
If you're interested in raven-js
. I've been with the try/catch
over Raven.context
as this won't create a new global closure around the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With