Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack: Should I build bundle on production server or build it locally and then upload?

I am deploying a React app on AWS Elastic Beanstalk. I bundle the app using webpack. However, I'm slightly confused about what best practices are from the production build process. Should I build the app locally (with NODE_ENV=production) using webpack, and then just upload the resultant bundle.js file, along with all node_modules to the Elasticbeanstalk instance? Or, should I upload all the source files, and run webpack on the actual cloud AWS server during deployment?

like image 738
rmacqueen Avatar asked Sep 08 '17 13:09

rmacqueen


2 Answers

You should never build for production locally (unless you're the only developer).

Ideally, you have a build process that gets triggered manually or automatically from a git commit which then builds your project for production for you.

By using a centralized build process, you can then be sure that all your builds are built the same way (e.g. same node version, same npm or yarn version).

like image 142
Noel Llevares Avatar answered Oct 17 '22 15:10

Noel Llevares


Both approaches are not really good to be honest. Local building is not a best way to build anything you want to have on production. You might have packages locally that may have inpact on what you're building. Same applies to the OS your doing it on.

And, again, same applies to the building during deployment. As the name of 'deployments' stands for, it's deploying. Just placing your application setup on the server so it may serve as it is supposed to.

That's the point where all CI/CD comes in. Having those kinds of solutions guarantee that each build is done with the same steps and on the same solution stack. No difference between each build is desired, because it allows you to assume that any bug or a change comparing to the 'desing' is because of the code, not environment it was build within.

Assuming that you're the only developer here (because you're asking for such a thing), CI/CD might be definitive overkill here, so just create shell script with steps and use Docker as the environment for build, so it stays the same between each build. That's the closest to the CI/CD option you can get without a hassle.

like image 34
mkubaczyk Avatar answered Oct 17 '22 17:10

mkubaczyk