Why do minified versions of libs break after being bundled?

Dear Mendix, I run into trouble when using minified libs in some widgets. The reason is that the bundled wdigets.js in wrapping the minified lib code. 'Heatmap/lib/d3-min':function(){ // wrapped by build app define(["dojo","dijit","dojox"], function(dojo,dijit,dojox){ // Minified version of d3 js. Ouch.... This fails!!! }); }, Versus normaly non minified lib 'Heatmap/lib/d3':function(){ // not wrapped.. d3 full version. Happy working code! }, Why is it wrapped, is this correct or a bug? Cheers, Andries
2 answers

The build toolset we use (npm + grunt + dojo) doesn't properly handle minified libraries. We've noticed that it mangles names of dependencies, which results in dependencies not being loaded properly at runtime.

We advise people to use unminified versions of libs for a few reasons:

  • the compression we employ on the webserver achieves 90% of the performance you'd get with minifying. in fact, if you have similar dependencies across widgets (ie multiple versions of jquery) it may actually be more efficient to use unminified versions.
  • debugging in case of errors is easier

My incomplete toughts upon this issue.

Mendix parses and processes the javascript files itself and tries to get all AMD lib references/define/require. This parsing can not handle minified versions because that would require a full javascript interpreter.

This is done to include 'cache' statements to improve the performance. According to your code it seems that it create a local scope for dojo, etc

That does not answer your question, but in my opinion it is a bug that it wraps the code.

In some widgets I found Mendix incorrectly notifying me of missing libraries. You can fool the parser by copying the define function into a local var and call that var instead of define. Mendix will not recognize that and allows running in the cloud.