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.
build
This is the public path of the application as can be seen inserver.ts
. This is where you would place all thecss
,images
, and customjs
files.dist
This is where thebuild-prod
script will dump all the transpiledserver code
for deployment. It will have the same file names (with .js extension) and folder structure asserver
folder.server
This 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
.client
This holds all you awesomeReact
pages and components. It basically handles all frontend matter.webpack
Contains webpack configurations
npm run dev
oryarn run dev
- This initiates anodemon
process that continueously watches all the.tsx
files in theclient
folder and regenerates the build artifacts on change.npm run serve
oryarn run serve
- This initiates anothernodemon
process that continueously watches all files inclient
andserver
folder, restarting the server each time a change is made.- Note that these two scripts must be running on different terminals during development
npm start
oryarn start
- Runs the development build of the application.npm run build
oryarn run build
- Creates the production build for the server (dist
folder)npm run build-img
oryarn run build-img
- Packages the application into a docker image (you need to edit this script and provide yourimage name/tag
)
git clone
this repository, copy files to your project folder- Run
npm install
oryarn install
to install all project dependencies - Open two terminals on the project folder
- Run
npm run dev
oryarn run dev
on one of the terminals - Run
npm run serve
oryarn run serve
on 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.