您在应用程序命名空间中注册的所有属性都可用于依赖(使用)您的应用程序包的包。因此,当您想在应用程序命名空间中注册包命名空间时,您需要在包中声明对应用程序包的依赖关系,并在应用程序命名空间中注册要导出的所有方法/对象。一个例子:
文件:packages/myapp/namespace.js
MyApp = {};
文件:packages/myapp/package.js
Package.on_use(function (api, where) {
api.add_files([
"namespace.js"
], ['client', 'server']);
api.export("MyApp", ['client', 'server']);
});
文件:packages/myapp-module1/logic.js
packageSpecificMethod = function(){}
moduleOne = {};
//you can export an module-specific namespace by registering it in the app-namespace
MyApp.module1 = moduleOne;
//or you can (if you dont want package-namespaces) register you private methods in the app-namespace directly
MyApp.exportedMethod = packageSpecificMethod;
文件:packages/myapp-module1/package.js
Package.on_use(function (api, where) {
api.use([
'myapp'
], ['client', 'server']);
api.add_files([
"logic.js"
], ['client', 'server']);
});