0

I’m a confused on what exactly the build script does and how it relates to deployment.

I know it it makes your project small by renaming variables, trimming white space, etc… but how does it work with deployment?

Do you only push the files that are generated by the build script?

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26
gmeeker99
  • 33
  • 3
  • Build can be assigned an action, but for create-react-app for example, this function minifies the files for the average browser use and dumps into a build directory. You should only need to deploy the build command output files to a local/hosted server. There can be dependencies you will have to troubleshoot based on your project. My instinct is to assume webpack is responsible with this minification and translation but not entirely sure. – S Henry May 09 '22 at 03:53
  • I am just using vanilla js for a very basic web app. I am deploying with heroku which according to their documentation uses a start script. So in that start script, would that action be the parcel build script? – gmeeker99 May 09 '22 at 15:22

1 Answers1

0

parcel build is used to create a production-ready bundle of files that can be deployed in various ways.

A very common workflow is to point parcel at an html file to build a client-side application that can be delivered by a file server (e.g. parcel build src/index.html). In this scenario, all the JavaScript is run by the user's browser, and the server is only responsible for serving the static files created by parcel build.

The core of the Heroku is a platform is focused on running server apps - i.e. apps that run most or a lot of their code on a server, not the browser. You mentioned the heroku "start" script (see docs), which is used in the context of such apps. If you're writing a heroku server application in, for example, nodejs, the start script would tell heroku what javascript file was the entry point to your node application (e.g. "start": "node dist/index.js". If you wanted to use parcel in such a project (e.g. to reduce the size of your server-side code so that heroku dynos might start up faster), you could run it in the context of a "build" command (e.g. "build": "parcel build/src/index.js").

If your application is entirely static html/js/css (i.e. the first scenario), I might consider another hosting platform like cloudflare pages or Amazon Amplify, which will probably be cheaper, faster and simpler. But if you want to use heroku, you need to set it up so that there is server code running that will deliver the static html/js/css files generated by parcel. There are many ways to do this - one would be to build a simple express app with the serve-static middleware, as described here.

Andrew Stegmaier
  • 3,429
  • 2
  • 14
  • 26