I'm using require.js's build tool (through grunt-contrib-requirejs) to pack up all my code into a minified version, and I've turned on generateSourceMaps.
However, the sourcemaps require is generating are wrong. In some files, they're fine, in others they're off by a line or two; in some, they're off by as many as 17 lines. What could be going wrong?
Possibly weird things about my repo:
- handlebars templates integrated into the build (they're precompiled, using Alex Sexton's plugin)
- a number of shimmed files that don't include require code standard (cordova, backbone, marionette).
- I am using r.js to concatenate files, but not to minify them. Minifying the files doesn't fix the problem (the same line errors occur).
- in some configurations, r.js gives an error that says it cannot generate source maps if preserveLicenseComments is on. In others (when not minifying), it seems to have no problem keeping license comments. Either way, turning it off does not help correct the line numbers.
- files that are listed later in the sourcemap header seem to have larger errors
What could be causing this, and how can I fix it?
UPDATE I've narrowed this down some: the sourcemap generator is losing a line every time it hits a line like this:
console.log('l170'); // logs as on line 170
//>>excludeStart('excludeHbsParser', pragmas.excludeHbsParser)
console.log('l172'); // logs as on line 171
I'm not precisely sure what the r.js parser is doing with these lines, but it does not seem to be accounting for them properly in the sourcemap generation.