Meteor npm server or client side

I was just wondering. How does meteor npm know if the module is client side only or server side only or both?

I’d say that Meteor analyzes which environment the file is loaded in and then decides how to load it, I don’t know the module system in-depth though.

If the file is located somewhere in a clients folder it loads it on the client, if it’s in an environment that’s reachable for both client and server it’s loaded on both environments.

So Is there a way to explicitly load a module for server-only? Eg, I’d like Lodash to be available only to server (it weights to much for the client).

Yes - the package will only be available wherever you import (require) it. If you only want lodash available on the server side, then just make sure your lodash imports are only ever used in server side files (e.g. /server/*, /import/server/*, etc.).

1 Like

What if it is an angular1 package such as angular-ui-bootstrap which is not a ES6 module yet. Or in general any non-ES6 module (i.e. ES5 code)

Should be the same thing - Meteor import syntax compiles to CommonJS require syntax, which it looks angular-ui/bootstrap supports.

Hmm you’re right that was a bad example. is a better example. That one does not have any require() function calls.