meteor / meteor-feature-requests

A tracker for Meteor issues that are requests for new functionality, not bugs.
Other
89 stars 3 forks source link

Allow us to remove MiniMongo from the client bundle #400

Closed timothyarmes closed 4 years ago

timothyarmes commented 4 years ago

The Mongo package currently pulls in MiniMongo on the client.

I'd like to use Mongo on the server, but I have no need for MiniMongo in the client build. It would be great if we could remove it.

dr-dimitru commented 4 years ago

@timothyarmes try replacing mongo package with:

npm-mongo
mongo-id
mongo-dev-server
binary-heap

That should be enough to run mongo on server only

timothyarmes commented 4 years ago

Fantastic, thank you!

Having done that I still had minimongo on the client. It's taken quite a while to track down the culprits and find a solution. In the end there were two packages that were pulling in either minimongo or mongo (which itself pulls in minimongo) into the client bundle: aldeed:collection2 and accounts-password.

I still needed them both on the server, so I removed them from my project and then created a tiny local package to pull them in on the sever side only. The package folder consists solely of this file (package.js):

Package.describe({
  name: 'local:server-only',
  version: '1.0.0',
  summary: 'Limits the scope of certain packages to be server side only',
});

Package.onUse((api) => {
  api.use('aldeed:collection2-core', 'server');
  api.use('accounts-password', 'server');
});

Everything runs perfectly and the client bundle is over 60kb smaller. Hopefully that'll help anyone else who needs to remove Minimongo.

Of course if you're doing this then you'll need to manage the accounts yourself on the client. I use Apollo with mutations to handle the login etc.

dr-dimitru commented 4 years ago

@timothyarmes yes! Of course, local packages are often a good solution to quickly manage code the way you need. Good catch 👍