Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap code in a custom closure during build process

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

like image 885
Simon Boudrias Avatar asked Jan 30 '13 21:01

Simon Boudrias


1 Answers

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.

like image 128
Simon Boudrias Avatar answered Oct 15 '22 14:10

Simon Boudrias