简体   繁体   中英

RequireJS - initialize one dependend module first, before loading the others

I am doing my first project with requireJS and instantly ran into a problem :)

I have created a module "main" which is the basic node where my app should initialize from. The APP uses a REST API to communicate with the server, so I created an API module, too.

The problem is: I have to initialize the API module first, before any other modules that are dependend of it will be loaded and initialized.

I have found it impossible to do that, because if my main module requires both the API module, plus some module dependend on the API module, the whole thing will failed, because they both get loaded and initialized before my main module gets initialized (and does the basic configuration of the API module).

Does someone know a trick how to load one module first, initialize it by passing some parameters and THEN go on and continue with requiring the other modules?

never tried it with Node.js but this works for me in both Dojo AMD and RequireJS assuming you need to run a module but before running the module B module A has to run i simply do this

require(["path/ModuleA","require"],function(modA,req){

    req(["path/ModuleB"],function(modB){
        //do anything with ModuleB
    });

});

i hope this solves your answer, if that's the issue you are referring to, take care

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM