Giter VIP home page Giter VIP logo

parcel-react-ssr's Introduction

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)
  • react-imported-component (Code Splitting)

Handy Extras

How to run

  • npm run dev - Run the development server with hot reload but no server-rendering
  • npm run build - Build for production, required before running
  • npm 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!

  1. package.json - Start by reading the scripts section to understand how the build process works. Yes it's that dead simple!
  2. app/index.html - Your only HTML file acting as a template
  3. app/client.js - Entry point for your browser version
  4. app/App.jsx - Your main application component shared between your browser and Node.js version
  5. app/HelloWorld.jsx - Dead simple hello world
  6. app/HelloWorld2.jsx - A fun code split example
  7. app/HelloWorld.scss - Example of SCSS
  8. server/index.js - Entry point for your Node.js version
  9. server/middleware.js - Middleware taking care of server-rendering
  10. server/generateHtml.js - Generate the HTML using index.html as the template with cheerio

parcel-react-ssr's People

Contributors

exon avatar krazyjakee avatar emiltholin avatar

Watchers

Noel Jackson avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.