I second the request. My use case is this. I already have a bunch of fine-grained folders: folder “author” contains “author.html” and “author.js”, etc.
I don’t want to further clutter my space with adding one-file “client” and “server” subfolders. If my “author” folder contains “author.html”, “client.js” and “server.js” and maybe a couple of other files, that’s the granularity I’d feel most comfortable with.
In fact, I came to this forum looking for a way to hack Meteor to do just that.
Wrap everything inside collections.client.js in a if(Meteor.isClient){ ... } block; and everything in collections.server.js in a if(Meteor.isServer){ ... } block.
You can name your files anything you want to help keep your code organized. You simply need to use the Meteor API to specify which code should be run where.
@awatson1978,
This solution does not work like server/ and client/ folders, because server code will be sent to client. So if you have a lot of server code or your server code contains some secure information, then this method fails.
@mrzafod,
Yes, it would work, but also it will force you to manually register all files in your project which is not a pleasure task.
@imkost Yep! This way has some limitation) But I suppose it is better to manage every file in a project and manage dependecies and load order by the hand. I have found this realy clear for building separate UI (templates + styles) for web/cordova or adding new features by api.use/api.imply. Give it a try - it could save the time later
Maybe you are right and I should give it a try. But also it would be nice if Meteor could cut off everything in if (Meteor.isServer) when serving to client.
I cant imagine how it could be done. Since a .js file is a scope with variables, contexts and closures it couldnt be cutted just with isClient isServer
if you create a client and a server folder, anything inside of the server folder only runs on the server, anything in the client folder only runs on client.
if you have a file inside of lib or anything other than server or client, then you could separate the code via Meteor.isServer or Meteor.isClient