Why are all my packages being loaded in my app even after I used the imports directory?

My project size has recently grow quite large and until recently I have been using pre 1.3 loading, no imports directory, just everything in client, server and lib.

Now that my project is getting larger, I decided to swap over to the imports system to prevent any unnecessary loading. After doing so however, it seems that unused packages are still being loaded in each template. For instance my landing page which is nothing more than some basic HTML is also loading collection2, googlemaps and other unused meteor packages as I can see under sources in chrome dev tools.

I thought these would only be imported into the view if I used " import { xx } from ‘meteor/xx’; " , not just imported everywhere by default. Am I experiencing something wrong or is this how it’s meant to be? Is there anyway to prevent unnecessary package loading if so?

Meteor compiles all your code into a single file and deliverrs it to the client. This means that any package you use (meteor add package), it will be in that file. (if ofcourse, that package has client-side code)

So far there is no known solution for lazy-loading such packages. It would be great though, maybe for future releases, it would be super amazing !

Thanks for helping me understand, since thats the case, whats the purpose of using the imports directory aside from controlling load order and I guess explicitly knowing the dependencies of a view? If everything is available everywhere, why bother to import it into every file that uses it specifically?

Well to keep it short:

  • Modular approach
  • Avoid globals
  • Control over file load order
  • Verbosity in your code. A new developer will know what comes from where. (Even yourself)

Imports (code in client folder) are only available where imported
Packages (old approach) are available where imported or globally, based on their package.js file and how they have been imported.