Meteor client/server common code shared between two apps

I would like to ask according to following discussion thread: Meteor 1.8.1 client and server directories in packages

How to solve the situation with the right way, when we are sharing common src between two meteor apps (we dont want tu use a private Npm/Atmosphere repo, but we are using a git submodule).

Currently, we created a /common folder (git submodule) in Meteor project root and inside common we have following file structure:

/common
/client
/server
/both

Does exists any way to prevent, If developer make a mistake and import code from /common/server into client?

Question2:
If I will make a mistake, and I will import server code into client. But the server code I will wrap into “if(Meteor.isServer) { …some code}”

After build the application, the server code will be will be physically present after compilation on client side or not?

If I remember correctly Meteor distinguishes the /server, /client folders in root, so in your case where everything is behind /common folder it can’t prevent accidental inclusion on client. That is something you will have to catch.
As for your second question I’m not sure if that is currently working or not. I think it will be that way in Meteor 2.0, but @renanccastro will probably know better.

1 Like

If I remember, client will not have access to any folder named server and vice-versa

Meteor.isServer is just a variable flag. It is not a build flag (also not sure for Meteor 2.0)

1 Like

@rjdavid …and is it possible to set somewhere also another directory to be available only for server? in my case (example /common/server).

…or if not, how can I configure eslint for checking it?

Thank a lot.

Why not try? It should be easy to verify

Yes, any folder with /server/ in it’s path will be excluded from the client.
So /common/server will be excluded from the client, as will foo/server/bar

@rjdavid I tested it and yes, you have truth. Sources inside if isServer are still there in dev and also in compiled production bundle.

@coagmano @rjdavid …does exist any way to prevent load sorces to client from folder /common/server? If not, can I configure eslint for check this?

Thanks a lot for your answers.

No need to configure anything. Meteor will refuse to load anything in any server folder or subfolder from the client

1 Like