[SOLVED] Remove collection2-core and simpl-schema from my client bundle


I’ve been playing around with bundle-visualizer and, in the process of trying to make my client bundle as small as possible (I’m obsessed), I found that collection2-core (7.3KB) and simpl-schema (39.8KB) are being added to my client bundle. Since I’m working with apollo and I’m defining my collections to be server side only, I would like to remove the above mentioned packages from my client bundle. Any suggestions?

I’ve tried adding a copy of collection2-core into packages folder in my root app and changing the api.export directive to api.export(‘Collection2’, [‘server’]); but the package is still showing in my client bundle. I guess it’s tightly coupled with Minimongo? I’ve also tried removing the minimongo dependency and removing all the client side code from the package but didn’t work either :frowning:

Here is the repo in case you want to take a look:

Any help would be really appreacited!


Is there a reason that you are using collection2 at all since you are using Apollo?

@copleykj To make sure I don’t insert wrong data when defining my mutations.

What’s your approach?

You could always just use simpl-schema for validations and forego collection2.

Currently collection2-core’s package.js calls api.mainModule without specifying the environment and thus will run it’s code on the server and client. If you are open having the package local you could specify this and it should prevent the additional code.

api.mainModule('collection2.js', 'server');

You will likely need to specify the server environment in the api.export as well

@copleykj Many thanks, I´ll try both approaches and let you know :grinning:

@copleykj I ended up writting a wrapper package to limit the scope of aldeed:collection2-core to be server side only.

In case someone else is interested, here is the meteor package:

And here the repo:

@copleykj Thanks for your help once again :slight_smile: