javascriptnode.jsnpmnpm-scriptsparceljs

What happens when you run the “build” script in parcel?


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?


Solution

  • 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.