This is a project template for server-side rendered react application with node all written in typescript.
build/
|___ css/
|___ images/
|___ js/
|
dist/
|___ server.js
|
server/
|___ server.ts
|___ tsconfig.json
|
client/
|___ components/
|___ pages/
|___ index.html
|___ index.tsx
|
webpack/
Normally, you would have to git ignore the build folder and the dist folder because these contain the actual artifacts that would be published. They are kept here for clarity.
buildThis is the public path of the application as can be seen inserver.ts. This is where you would place all thecss,images, and customjsfiles.distThis is where thebuild-prodscript will dump all the transpiledserver codefor deployment. It will have the same file names (with .js extension) and folder structure asserverfolder.serverThis is where you would write you server side code all intypescript. Where you will managedata, convert your components tostring, and send back to the user as purehtml.clientThis holds all you awesomeReactpages and components. It basically handles all frontend matter.webpackContains webpack configurations
npm run devoryarn run dev- This initiates anodemonprocess that continueously watches all the.tsxfiles in theclientfolder and regenerates the build artifacts on change.npm run serveoryarn run serve- This initiates anothernodemonprocess that continueously watches all files inclientandserverfolder, restarting the server each time a change is made.- Note that these two scripts must be running on different terminals during development
npm startoryarn start- Runs the development build of the application.npm run buildoryarn run build- Creates the production build for the server (distfolder)npm run build-imgoryarn run build-img- Packages the application into a docker image (you need to edit this script and provide yourimage name/tag)
git clonethis repository, copy files to your project folder- Run
npm installoryarn installto install all project dependencies - Open two terminals on the project folder
- Run
npm run devoryarn run devon one of the terminals - Run
npm run serveoryarn run serveon the other terminal - Navigate (using a browser) to the port your server is listening and rock on!
I would love to see all the awesome ways you'll edit and reconfigure this template. Feel free to contribute if you see where we can make it better.