In getS3.server.js I import aws-sdk and this is the only place where I import it in the entire app (and the only place where I import or require getS3.server.js).
However, if I run bundle-visualizer, I can see aws-sdk in the chart (which is huge).
Is this normal? How can I avoid bundling it to the client or see the packages actually delivered?
Yes, bundle-visualizer will only show packages on the client, which does mean that the aws-sdk is being shipped to the client.
The reason why is that the bundler uses static analysis to compile the bundle (ie. reads the import and require statements to see what needs to be included).
There’s a couple of solutions you can use to solve this:
Put getS3.server.js inside a server/ directory. Meteor will never bundle this for the client, meaning it’s dependencies also won’t be loaded. This means require will throw on the client, but you’ve already got it behind an if (Meteor.isServer) test so all good! (This is what I personally use)
Thanks for the answer. What I don’t understand is that I thought if I specify mainModule in package.json, the import behavior changes and meteor will only include the files which I explicitly import somewhere (starting from the specified entry point). So I don’t have to use the magic import folder.
Does this mean that everything outside of a server folder will be bundled for the client no matter the entry point and the import statements?