You can use this project as a boilerplate for your SSR applications. Feel free to suggest improvements If you are looking for renderToPipeableStream setup switch to the feat/pipable-stream branch
-
SSR
-
HMR
- Code splitting
-
SPA
mode -
Polyfills
-
PWA
- React forget
- local
https
-
PipeableStream
support
- If you want to try React 18's SSR Suspense api such as
renderToPipeableStream
, switch to the feat/pipable-stream branch. - Also, there is en example for setting up suspense api with CSS-in-JS library in our case MUI just switch to the feat/suspense-mui branch.
- I also wrote a small article about
SSR with React 18
. For those interested in further information, feel free to check my post on medium
Before starting work with the project, run the command:
yarn install
If you need to use https, follow these steps:
- in
setup.sh
change thedomain
variable to your domain - run the command
yarn setup
- finally add your CLIENT_HOST variable to .env file as
https://<YOUR-domain>:PORT
You can use .env file to specify environment variables. This file is ignored by git.
- Add it to
.env
file - For TS completion and validation add it to
envSchema
insrc/common/env/index.ts
- If this variable needs to be accessible from both
client
&server
make sure it's name starts with prefixCLIENT_
- You can change client (
CLIENT_
) prefix inwebpack/plugins/define.plugin.ts
- You can access environment variable via
getENV
function. This function will return a proper value based on environment (client/server) and cast it to a proper type based onenvSchema
fromstep 2
(string/number/boolean) - Important note! Unlike with Next.js apps, environment variables in this setup are
not baked
into thebundle
at build time. This allows you tobuild
the apponce
(e.g., for staging) andreuse
the same build in other environments, such as production, without needing to rebuild for each environment.
Note that additionally there will be few useful global variables
available for you.
IS_DEV
,IS_PROD
,IS_SERVER
,IS_SPA
To start the project in SSR mode, run the command
yarn dev
To start the project in SPA mode, run the command
yarn spa
To start the project in Prod mode, run the command
yarn start
Ready! The app will start on http://localhost:3000