0

I am currently refactoring the javascript portions of a web site, and now I have bundled some scripts together using Browserify. The resulting script is bundled along with other resources using SquishIt. In Debug mode, when SquishIt is not bundling all the scripts together everything seems to work just fine, but when running in Production, and SquishIt bundles everything together I get errors from the Browserify part of my bundle. The error is complaining that r has no length property (see line 18) below. This part of the code is created by Browserify when bundling the scripts.

(function e(t, n, r) { function s(o, u) { if (!n[o]) { if (!t[o]) { var a = typeof require == "function" && require; if (!u && a) return a(o, !0); if (i) return i(o, !0); var f = new Error("Cannot find module '" + o + "'"); throw f.code = "MODULE_NOT_FOUND", f } var l = n[o] = { exports: {} }; t[o][0].call(l.exports, function(e) { var n = t[o][1][e]; return s(n ? n : e) }, l, l.exports, e, t, n, r) } return n[o].exports } var i = typeof require == "function" && require; for (var o = 0; o < r.length; o++) s(r[o]); return s })({

I really can't think of anything that using SquishIt to bundle all the scripts would break the logic of the browserified scripts. What could be the cause of this? This gist shows the entire source code, in case that is relevant.

I have not changed anything on the ASP.NET side (in the bundling), and the relevant part of my ´Head.ascx´ looks like this:

 Bundle.JavaScript() 
 .Add(Assets.JavaScript.GetUrl("main.js").ToString()) 
 .Add(Assets.JavaScript.GetUrl("Plugins/raphael-min.js").ToString()) 
 .Add(Assets.JavaScript.GetUrl("Plugins/vector_map.js").ToString()) 
 // more ...
 .Render("~/Content/"+Assets.VersionString+"/Scripts/Combined/combined.js")
oligofren
  • 20,744
  • 16
  • 93
  • 180

1 Answers1

1

Have a look at this comment it may help https://github.com/jetheredge/SquishIt/issues/320#issuecomment-139921409

Is there a reason you need to use two different bundling solutions?

AlexCuse
  • 18,008
  • 5
  • 42
  • 51
  • Thanks! I found out by inspecting the minified output that SquishIt (or some minifier included with it) destroyed the closures produced by browserify; "unwrapping" them and getting the dependencies out of order. This made us turn to the built-in ASP.NET bundler which worked fine, but the minifying produced errors that showed that we included some untranspiled ES6 lambda/arrow functions that might be the reason why SquishIt broke down. – oligofren Apr 27 '16 at 06:18
  • As to why we use two different bundling solutions, I recently took over this legacy project, trying to clean it up and bring in modern FE practices. Using Browserify I can get rid of globals by moving one script at a time over to CommonJS while not touching everything else. – oligofren Apr 27 '16 at 06:22
  • 1
    In that case I'd try switching to the included YUI minifier first. If that doesn't work there is a beta package for SquishIt v1.0 available on Nuget that uses more recent versions of both minifiers. There are some significant changes coming still but I think its probably in decent shape to use. https://www.nuget.org/packages/SquishIt/1.0.0-beta2 – AlexCuse Apr 28 '16 at 20:51