Frage

I am working on a JavaScript project where we use requirejs to manage our code. The product we create is to be used on 3rd party web sites, and therefore we cannot assume that an AMD compatible library is present. To solve this, we include almond in our target file and expose our main module on window. The file created by our build looks like this:

(function() {
    //Almond lib

    //Our code

   define('window-exposer', ['main-module'], function(mainModule) {
       window.mainModule = mainModule;
   });

   require('window-exposer');
}());

When building a site that want to use mainModule an error is thrown because when the site specific code tries to access window.mainModule it has not been set yet. There are also cases where the module has indeed been initialized and the code works.

Is there any way to guarantee that the window-exposer is run before other JavascriptCode is?

War es hilfreich?

Lösung

I solved it by using the solution provided here https://github.com/jrburke/almond#exporting-a-public-api

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top