0

I'm using Grunt to build a project: uglify for authored JS files and then concat with libs that are already minified.

The minified libs already have sourcemaps.

Is it possible to merge them with the ones generated by uglify for the authored JS files?

The final app.js file is made up of blocks of code ending with the sourcemap comment like this:

[Minified library code]
//# sourceMappingURL=library.map

[Minified authored code]
//# sourceMappingURL=script.map

That messes up the minified->original matching. Random files and lines are associated with code elsewhere in the original files.

Is there anything I can do without having to use separate files?

Thanks.

Francisc
  • 77,430
  • 63
  • 180
  • 276
  • 1
    This thread can be interesting: https://groups.google.com/forum/#!topic/closure-compiler-discuss/eDV41-xD87g And they mention this link as well: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt Actually there is no full solution there, but maybe it helps if you would like to implement something. – Lajos Veres Mar 22 '14 at 08:52
  • 1
    Have a look at https://github.com/thlorenz/combine-source-map. That would merge the sourcemaps together, but you'd still work out a way to get the sourcemap comments the way you want them at the end of the `app.js` file. – Wallace Sidhrée Mar 22 '14 at 09:15
  • @Francisc Do you still remember what did you end up doing? I am in a similar situation. Thanks! – newbie May 01 '19 at 21:47

1 Answers1

1

Why don't you run the uglify task as the last element in the Grunt tasks queue? Or at least after concat. This way you should be able to add just a single source map comment, pointing to the file generated by concat and let uglify creates the minified version with the correct source map.

Also, remember that you could pass a sourceMapIn parameter to uglify to include source map(s) to earlier compilations.

Luca Lenardi
  • 105
  • 1
  • 5
  • Hi, Luca. The idea is that library code (e.g. AngularJS) is already minified and already has a sourcemap. I don't want to run uglify over it as I believe the Angular team knows better. Do you know of any examples of using `sourceMapIn`? Before posting I read about it as well as `sourceMapIncludeSources`, but I found no demos or clear docs about using them. – Francisc Mar 22 '14 at 23:11
  • Ok, so if I understand correctly what you need, you should absolutely have a look at this tiny lib called [`combine-source-map`](https://github.com/thlorenz/combine-source-map), which basically compose a single source-map from different files (and their related maps). You can create a simple **task** for grunt at the end of your tasks queue to use it and that should do the trick. – Luca Lenardi Mar 25 '14 at 14:06