Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source maps with grunt

Do you know of a workflow that includes source maps for an app compiled with grunt?

I am well aware of plugins like uglifyjs that allow you to simply generate a source map. But I'm looking for incorporating this into a more complex workflow, rather than just making a one-off source map.

I've noticed that the most popular Yeoman generators (that I know of) are missing source maps in their workflows. Is this just because of a lack of support in the major plugins for source maps? Or is it instead that source maps aren't necessary in work flows, and I just can't think of a clever enough alternative?

Notable sources of trouble with popular grunt plugins that I've run into include:

uglify being unable to handle even the most basic of project structures without a hacky fix.

usemin also being unable to handle source maps beyond the simplest of configurations, in that it can really only support one per project (but still requires a hack to correct it). A possible solution is obviously to stop using usemin altogether, but then you lose out on all of the benefits of it, like pairing it with rev, watch, and connect.

I'm thinking that my best course of action might be testing with un-concatenated/not-minified sources when I'm testing my app. This is, of course, less than ideal, as I'd like my test environment to mirror the production one as best as possible.

Do you use source maps in your grunt project? How do you do it? If not, how do you get around the lack of support for them?

like image 507
jamesplease Avatar asked Nov 01 '13 02:11

jamesplease


1 Answers

Updates 02/17/14

Z Goddard and I are working on fixing up source maps across the grunt-contrib suite. The planned options for the entire suite can be read about in this repo. We're also working on a new library, sourcemap-util, that will provide helper functions for generating source maps with any library. I'll update this when there's more progress.


I've done enough research to now be able to answer my own question.

No, there is not really any good way to handle source maps right now with grunt.

Both usemin and grunt-contrib-uglify need updates for this to work as I'd like. I submitted a pull request to grunt-contrib-uglify that is a good start on better source map support. With luck, this pull will be merged.

As for usemin, I disagree with its approach to handling dependencies. I've begun a separate project, grunt-resourceful, that goes about things differently. That project is still in its infancy, so I don't suggest using it now. I'll update this once 1.0.0 is released.

like image 61
jamesplease Avatar answered Nov 03 '22 22:11

jamesplease