parcel-react-ssr
v0.4.0
Published
Example of SSR with React and ParcelJS
Downloads
18
Readme
parcel-react-ssr
Simple example of how to do server-rendering. You will not believe how easy it is!
Using:
- parcel-bundler
- react
- react-router-dom
- react-helmet (SEO)
How to run
npm run dev
- Run the development server with hot reload but no server-renderingnpm run build
- Build for production, required before runningnpm start
- Start the production server
How does it work?
To do proper server-rendering, the code is bundled in two version: one for the browser and one for Node.js.
The browser version is in the dist/client
folder and the Node.js version is in dist/server
. However, they both share the same public path for their files: /dist
and it points to the browser version. Go read the code, it's pretty straightforward!
Read the code!
- package.json - Start by reading the
scripts
section to understand how the build process works. Yes it's that dead simple! - app/index.html - Your only HTML file acting as a template
- app/App.jsx - Your main application component shared between your browser and Node.js version
- app/HelloWorld.jsx - Dead simple hello world
- app/HelloWorld.scss - Example of SCSS
- server/index.js - Entry point for your Node.js version
- server/middleware.js - Middleware taking care of server-rendering
- server/generateHtml.js - Generate the HTML using
index.html
as the template with cheerio