Should I bundle my Express server code to run node on the bundle, rather than my unbundled app.js with tons of requires?

Viewed 502

Two questions, all related to bundling. First server, then client.

Typically, I wrote my Express server code, using an app.js file to setup my express server, setup logging, routes, etc. I also ran tests against the functions associated with the routes.

When deploying my server code to AWS, I would push the code and a git hook would build the project by doing an npm install, run my task runner to bundle client files and to copy files to their dist directories.

For my client side code, I used to use browserfy, then moved to webpack to bundle all my client code to a single bundle or main.js.

I'm looking at using rollup now and appreciate its' ability for tree shaking.

As I'm now setting up a new project, I have a few questions/concerns:

  1. Should I also bundle on the node/server-side? Is it more efficient for the server to run against an optimized, tree shaken, server bundle? Or once node interprets my unbundled app.js, it's pulled into memory along with all the require files and would run similar to the same bundled/tree shaken version.

  2. I currently deploy code to an aws server via a git push. That push triggers a full build server side, moves client files to dist directories and starts the nginx and node servers. Should I instead run the build process locally and only push dist files to the server? Thinking about a CI/CD process, I'm thinking no... but it could happen... But is it worth it? Depends a lot on answer 1, and maybe some hybrid approach.

Maybe someone could outline their production deploy steps at a high level? I can also talk more on mine if interested.

0 Answers
Related