Create single binary from express + react app with zeit pkg?

798 Views Asked by At

How do I package an express + react folderstructure into a single binary with zeit? I can run each of them like this: node server.js npm run start client

I can start both like this: scripts element in package.json: "myapp": "concurrently --kill-others \"node server\" \"npm run --prefix client start\"",

then - npm run myapp in the same folder as package.json.

What I would like to achieve is to apply zeit/pkg somehow so that I have a single binary that I can run that starts both servers in the same way as npm run myapp.

Anyone who knows how?

1

There are 1 best solutions below

0
On

I don't think zeit/pkg accepts multiple entry points based on their documentation

The entrypoint of your project is a mandatory CLI argument. It may be:

Path to entry file. Suppose it is /path/app.js, then packaged app will work the same way as node /path/app.js
Path to package.json. Pkg will follow bin property of the specified package.json and use it as entry file.
Path to directory. Pkg will look for package.json in the specified directory. See above.

Maybe the better route would be to do some server-side rendering via their Next.js framework? Then you would only have to package your app via the NodeJS entry point.