This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/public/assets/scripts/discourse-boot.js
David Taylor 569fa8a135
DEV: Improve Ember module shims under Ember CLI (#15795) (#15806)
In our legacy environment, Ember RFC176 shims are included in `discourse-loader.js` which is part of the `vendor.js` bundle. This meant that the module shims were available as soon as the vendor.js asset was loaded.

Under Ember CLI, we were defining these shims in `discourse-boot.js`. This is loaded by the browser much later, and meant that the shims were not available to themes/plugins that call `require()` before Discourse has booted. This was causing errors under some circumstances.

This commit refactors the Ember CLI implementation so that the shims are included in the vendor.js bundle. This is done via an addon which leans on the ember-rfc176-data NPM package. This will ensure we have all the definitions, without the need for manual copy/paste.
2022-02-03 17:36:32 +00:00

32 lines
991 B
JavaScript

(function () {
if (window.unsupportedBrowser) {
throw "Unsupported browser detected";
}
// TODO: Remove this and have resolver find the templates
const prefix = "discourse/templates/";
const adminPrefix = "admin/templates/";
let len = prefix.length;
Object.keys(requirejs.entries).forEach(function (key) {
if (key.indexOf(prefix) === 0) {
Ember.TEMPLATES[key.substr(len)] = require(key).default;
} else if (key.indexOf(adminPrefix) === 0) {
Ember.TEMPLATES[key] = require(key).default;
}
});
window.__widget_helpers = require("discourse-widget-hbs/helpers").default;
// TODO: Eliminate this global
window.virtualDom = require("virtual-dom");
let element = document.querySelector(
`meta[name="discourse/config/environment"]`
);
const config = JSON.parse(
decodeURIComponent(element.getAttribute("content"))
);
const event = new CustomEvent("discourse-booted", { detail: config });
document.dispatchEvent(event);
})();