Trying to build three different apps to serve different kinds of users in a single project. For example, three different users : admin, author and learner (very light weight app with just few screens). The layout of app and screens will be different for all three users, but will share same MongoDB database.
Would like to have only specific app JS code loaded to browser based on specific user, but with Meteor not sure how to structure code or configure to achieve it loads only specific JS code. Also not sure how to build device app for only specific kind of user.
Thinking to use following folder structure to organize the code, but how can I config Meteor to load only specific folder’s code based on layout / router config or some other technique.
Folder structure could be
common/lib, common/server, common/client, common/public
admin/lib, admin/server, admin/client, admin/public
author/lib, author/server, author/client, author/public
learner/lib, learner/server, learner/client, learner/public
One way to do it would be to create a package that contains all the common code, then separate applications that use the common package. This would allow you to reuse code without putting admin code in a client app, for example.
That said, however you split your apps, all client side code is downloaded when the user visits the correct url or app regardless of whether they are logged in or not. So really you shouldn’t have any sensitive code outside of the server folder.
There are some packages out there that allow for lazy loading, although I don’t know much about them or how well they work. This would solve your problem of only loading the specific JS you need. However, if you aren’t concerned about the client loading extra JS files, you can just create a beforeHook in iron-router that checks what role the user has (use alanning:roles package), and directs the user to the appropriate route. I had three different roles in my app, and this works fairly well. If you have questions on how to do it, I can provide additional details.
If you really want to separate your client codebase into different apps, you could make separate meteor projects for each role and use symbolic links (ln -s) to share common directories.