Example of building a React fullstack application or static site
Node.js must be installed, with its package manager, npm.
To create a new project based on this example, clone this repository and give it a new name.
git clone --depth 1 https://github.com/TangibleInc/react-builder-example app-nameGo into the created project, and remove the .git folder.
cd app-name
rm -rf .gitRun git init to start a new repository as needed.
npm installBuild during development - watch files and rebuild
npm run devAfter running this command, it will wait and rebuild scripts and styles as you edit the files.
When you're done, press CTRL+C to exit the process.
Export as static site
npm run exportThe folder build/public will contain the complete site.
Create a file called deploy at the root of the application.
touch deploy && chmod +x deployThe deploy script should sync the static site to a remote server.
Example:
#!/bin/bash
rsync -vrlptz --delete ./build/public/ user@server:apps/app-nameNote the trailing / which is required for the source.
Run the following to deploy after export.
./deployFor a fullstack application, PM2 is the recommended process manager.
This project includes pm2.config.js, and NPM scripts in package.json to start/stop the application process. The default build command copies files needed for production to the build folder.
Copy the file .env.development to .env.production.
cp .env.development .env.productionThe development env file is used for local development. Define all environment variables required by the application server.
The production env file must define the same set of environment variables for the production server. It is excluded from Git.
Build for production
npm run buildThis following command runs the built server in production mode, as a test run.
npm run tryFollow the same step as a static site, and create a deploy script.
Change the rsync source to the whole build folder, to sync client and server.
rsync -vrlptz --delete ./build/ user@server:apps/app-nameThen add a line to restart the application after deploy.
ssh user@server "cd ~/apps/app-name && npm run restart"Run the following to deploy after build.
./deploy