Is it possible to exclude a package from the client bundle?

I am using the package jagi:astronomy, which is adding about 120kb to my client-side bundle. Because I wasn’t really using much of their client-side logic, I removed all references to it on the client side, and instead I send plain objects over the wire.

I was hoping that when I have an Astronomy package that is not referenced or imported, it would not be included in the client bundle. From the docs, I see that if a package is included with api.mainModule(..., 'client', { lazy: true}), then it is not included in the client bundle if no importing code is found.

Well, jagi:astronomy uses this format, but my code is still present in the bundle. I dove deeper into isobuild than I would like to admit, and I see that the package is added not because it’s referenced by another package, but because it is referenced in .meteor/packages and is thus an app constraint.

/* jagi:astronomy package.js */
api.mainModule("lib/main.js", ["client", "server"], { lazy: true });

Could someone tell me if I’m misunderstanding {lazy: true} or if there’s something else I’m not doing correctly? I would love to create a bundle where jagi:astronomy is available on the server, but not on the client.

1 Like

You can just remove the client from the package export.

api.mainModule("lib/main.js", "server");

To do that, I’d need to clone the package into my codebase to make the change, right?

yes. the package should be in your codebase in the “packages” folder.