This project provides a comprehensive template for setting up server-side rendering (SSR) with React. It includes a custom loader for handling .jsx
files in Node.js, an on-the-fly bundler for both server and client code, and an example implementation of SSR, including bundle generation for the browser and hydration.
To use this loader, you need to have Node.js 20.15.0+ installed.
-
Clone this repository:
git clone https://github.com/Artexoid/react-basic-ssr-template.git
-
Install the dependencies:
npm install
You can run your Node.js project with this loader by using the following command:
node --import ./loader/register-hooks.mjs ./app/index.mjs
This command will load your JSX files, transpile them to regular JavaScript, and create a bundle on the fly for server-side rendering.
You can start it with PM2 using the following command:
pm2 start /root/.nvm/versions/node/VARSION/bin/node --cwd /var/www/ROOT_DIR -- --import ./loader/register-hooks.mjs ./app/index.mjs
loader/
: Contains the custom loader code.app/
: Contains the example application code.
This project is licensed under the MIT License.
Artem Goncharuk
If you have any questions or feedback, feel free to reach out or open an issue on GitHub.
Contributions are welcome! Please feel free to submit a pull request.
This project is maintained by Artem Goncharuk.