danhammond
05/05/2022, 11:26 AMready function so I can queue the ready event handlers, wait for my Vite script to load, then de-queue and call the handlers
In the loader:
js
const ready = $.prototype.ready;
let queued = [];
$.prototype.ready = function ( fn ) {
  queued.push( fn );
};
$.enableReady = function() {
  queued.forEach((x) => {
    ready.call(this, x);
  })
  
  $.prototype.ready = ready;
}
let script = document.createElement("script");
script.type = "module";
script.src = "/backoffice/src/main.ts";
document.getElementsByTagName('head')[0].appendChild(script);
In my Vite script:
js
if ( $.enableReady ) {
  $.enableReady()
}