43

Is there any way to set up the default System.Web.Optimization.ScriptBundle to generate source maps for the bundled and minified files? Is there an equivalent solution, other than having to pre-generate the bundles and source maps before each build?

Mihai
  • 2,835
  • 2
  • 28
  • 36
  • Have you found the solution? – Rajesh Dhiman Jan 28 '14 at 14:45
  • I haven't found a ready-made solution yet. Once I have some free time, I'll see if I can write something myself; I'll post an answer then. – Mihai Jan 28 '14 at 15:14
  • If you have VS 2013, you can use the new Task Explorer VSIX plugin. Read about one approach [here](http://icanmakethiswork.blogspot.com/2014/11/using-gulp-in-visual-studio-instead-of-web-optimization.html). I'm considering getting gulp working without the plugin in VS2012 as an option. The main pain point is getting node.js, NPM, etc. all set up on my CI servers. – jessewolfe Dec 03 '14 at 02:51

2 Answers2

22

It looks like in the meantime some kind soul has released a custom class that does exactly what I need.

You can get his source at https://github.com/benmccallum/AspNetBundling.

Mihai
  • 2,835
  • 2
  • 28
  • 36
  • 7
    What @Kurt said is simply untrue. In any means, I've updated the github repo to include a test website. I encourage him to clone the repo, attach a debugger into the `ScriptWithSourceMapBundleBuilder.BuildBundleContent(...)` method and see that the WebOptimization framework only calls IBundleBuilder.BuildBundleContent once on first request of contents, at which time I also generate the .map file. – benmccallum Mar 15 '15 at 06:09
  • 1
    You can now get the source from the below NuGet package https://www.nuget.org/packages/AspNetBundling/ – zlsmith86 Dec 11 '15 at 20:58
6

Nothing built in yet, although I wish it was. That being said, if you don't have to use the built in optimizer you could opt for Web essentials found here and use it to create bundles with map files for you. These bundles are kept up to date as you save changes to the source js files so you would not need to recreate the bundles per build.

Right click on any script file once web essentials is installed, select the web essentials option at the top of the context menu, and select minify javascript file. Alternatively you can select multiple javascript files and use web essentials to create a bundle in the same fashion.

grossadamm
  • 454
  • 3
  • 17
  • Using `ScriptBundle` will create a `/bundles` directory and auto append a random GUID so the browser knows this is a new bundle version and the cache is circumvented. Web Essentials does not support cache busting, correct? – styfle Jul 07 '14 at 23:46
  • Unfortunately, I couldn't tell you now as I've moved onto another project in rails. We were using varnish for our caching solution so we didn't run into the issue as we could bust the cache on demand. I don't recall if web essentials was using some kind of guid to bust the cache for you or not.... – grossadamm Jul 08 '14 at 18:13
  • It appears Mads (the author of Web Essentials) wrote [this solution for cache busting](http://madskristensen.net/post/cache-busting-in-aspnet). – styfle Jul 09 '14 at 00:25