Obtain an instance of jQuery in External File .js in HTMLSnippet

0
This is not a question, I’m sharing the knowledge. HTMLSnippet from Marketplace has a radio option “JavaScript with jQuery”, but when an "External File" is used this option does nothing. I checked the source code of HTMLSnippet and found that it calls: require(["jquery"]) inside _evalJQueryCode (), but _evalJQueryCode  is not called in external file mode. I tried to call require(["jquery"]) in my custom javascript, but it fails with 404. I checked again and found that in the compiled HTMLSnippet.js “require” gets converted to “__webpack_require__”  which is not visible from my custom javascript. I managed to obtain the instance of the widget and steal its jQuery by calling _evalJQueryCode (): // External file part // widget-treetable-wrapper is not rendered yet var thissnippet = dijit.getEnclosingWidget(document.currentScript.parentNode); thissnippet._my_snippet = function($) { // Inline js part // ... }; thissnippet.contents = "this.widget._my_snippet($);"; // Hack: because jquery is in webpack we can't call require(["jquery"]) directly thissnippet._evalJQueryCode(); By the way, a new cache id is appended to the external file URI every time you navigate to the page with HTMLSnippet which breaks resource caching and makes the previously set breakpoints unusable. I think it’s a bug.
asked
0 answers