JavaScript dependency management

后端 未结 6 1909
清歌不尽
清歌不尽 2020-12-08 08:06

I am currently maintaining a large number of JS files and the dependency issue is growing over my head. Right now I have each function in a separate file and I manually main

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 08:26

    Have you tried using a dependency manager like RequireJS or LabJS? I noticed no one's mentioned them in this thread.

    From http://requirejs.org/docs/start.html:

    Inside of main.js, you can use require() to load any other scripts you need to run:

    require(["helper/util"], function(util) {
        //This function is called when scripts/helper/util.js is loaded.
        //If util.js calls define(), then this function is not fired until
        //util's dependencies have loaded, and the util argument will hold
        //the module value for "helper/util".
    });
    

    You can nest those dependencies as well, so helper/util can require some other files within itself.

提交回复
热议问题