我正在开发一个需要外部 api 的流星智能包。我需要加载 api,然后在加载 api 后加载一个使用该 api 的文件。
在智能包中定义这样的加载顺序的正确方法是什么?
If you've added your smart package into your meteor project the package will be loaded before your meteor code runs.
If you mean in your API you're going to be loading stuff and the loading order matters there, the order that you use api.add_files
in would be used. (See example : https://github.com/avital/meteor-xml2js-npm-demo/blob/master/packages/xml2js/package.js)
So if you want to do something after all the other files have loaded I guess you could just put the code for that in file and add it as the last api.add_files
.
For code in around the meteor directories and folders, the load order is (as from the meteor docs):
Files in the lib directory at the root of your application are loaded first.
Files that match main.* are loaded after everything else.
Files in subdirectories are loaded before files in parent directories, so that files in the deepest subdirectory are loaded first (after lib), and files in the root directory are loaded last (other than main.*).
Within a directory, files are loaded in alphabetical order by filename.